diff options
Diffstat (limited to 'framework/src/maven/apache-maven-3.3.3/maven-artifact')
33 files changed, 5670 insertions, 0 deletions
diff --git a/framework/src/maven/apache-maven-3.3.3/maven-artifact/pom.xml b/framework/src/maven/apache-maven-3.3.3/maven-artifact/pom.xml new file mode 100644 index 00000000..206d72b8 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-artifact/pom.xml @@ -0,0 +1,58 @@ +<?xml version="1.0" encoding="UTF-8"?> + + <!-- + 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. + --> + +<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/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.maven</groupId> + <artifactId>maven</artifactId> + <version>3.3.3</version> + </parent> + + <artifactId>maven-artifact</artifactId> + + <name>Maven Artifact</name> + + <scm><!-- remove when git scm url format can accept artifact-id at the end, as automatically inherited --> + <connection>scm:git:https://git-wip-us.apache.org/repos/asf/maven.git</connection> + <developerConnection>scm:git:https://git-wip-us.apache.org/repos/asf/maven.git</developerConnection> + <tag>maven-3.3.3</tag> + </scm> + + <dependencies> + <dependency> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-utils</artifactId> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-component-metadata</artifactId> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jar-plugin</artifactId> + <configuration> + <archive> + <manifestEntries> + <Main-Class>org.apache.maven.artifact.versioning.ComparableVersion</Main-Class> + </manifestEntries> + </archive> + </configuration> + </plugin> + </plugins> + </build> +</project> diff --git a/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/Artifact.java b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/Artifact.java new file mode 100644 index 00000000..6cc00226 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/Artifact.java @@ -0,0 +1,161 @@ +package org.apache.maven.artifact; + +/* + * 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. + */ + +import java.io.File; +import java.util.Collection; +import java.util.List; +import java.util.regex.Pattern; + +import org.apache.maven.artifact.handler.ArtifactHandler; +import org.apache.maven.artifact.metadata.ArtifactMetadata; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.resolver.filter.ArtifactFilter; +import org.apache.maven.artifact.versioning.ArtifactVersion; +import org.apache.maven.artifact.versioning.OverConstrainedVersionException; +import org.apache.maven.artifact.versioning.VersionRange; + +/** + * Maven Artifact interface. Notice that it mixes artifact definition concepts (groupId, artifactId, version) + * with dependency information (version range, scope). + */ +public interface Artifact + extends Comparable<Artifact> +{ + + String RELEASE_VERSION = "RELEASE"; + + String LATEST_VERSION = "LATEST"; + + String SNAPSHOT_VERSION = "SNAPSHOT"; + + Pattern VERSION_FILE_PATTERN = Pattern.compile( "^(.*)-([0-9]{8}.[0-9]{6})-([0-9]+)$" ); + + // TODO: into artifactScope handler + + String SCOPE_COMPILE = "compile"; + + String SCOPE_COMPILE_PLUS_RUNTIME = "compile+runtime"; + + String SCOPE_TEST = "test"; + + String SCOPE_RUNTIME = "runtime"; + + String SCOPE_RUNTIME_PLUS_SYSTEM = "runtime+system"; + + String SCOPE_PROVIDED = "provided"; + + String SCOPE_SYSTEM = "system"; + + String SCOPE_IMPORT = "import"; // Used to import dependencyManagement dependencies + + String getGroupId(); + + String getArtifactId(); + + String getVersion(); + + void setVersion( String version ); + + String getScope(); + + String getType(); + + String getClassifier(); + + boolean hasClassifier(); + + File getFile(); + + void setFile( File destination ); + + String getBaseVersion(); + + void setBaseVersion( String baseVersion ); + + String getId(); + + String getDependencyConflictId(); + + void addMetadata( ArtifactMetadata metadata ); + + Collection<ArtifactMetadata> getMetadataList(); + + void setRepository( ArtifactRepository remoteRepository ); + + ArtifactRepository getRepository(); + + void updateVersion( String version, ArtifactRepository localRepository ); + + String getDownloadUrl(); + + void setDownloadUrl( String downloadUrl ); + + ArtifactFilter getDependencyFilter(); + + void setDependencyFilter( ArtifactFilter artifactFilter ); + + ArtifactHandler getArtifactHandler(); + + List<String> getDependencyTrail(); + + void setDependencyTrail( List<String> dependencyTrail ); + + void setScope( String scope ); + + VersionRange getVersionRange(); + + void setVersionRange( VersionRange newRange ); + + void selectVersion( String version ); + + void setGroupId( String groupId ); + + void setArtifactId( String artifactId ); + + boolean isSnapshot(); + + void setResolved( boolean resolved ); + + boolean isResolved(); + + void setResolvedVersion( String version ); + + void setArtifactHandler( ArtifactHandler handler ); + + boolean isRelease(); + + void setRelease( boolean release ); + + List<ArtifactVersion> getAvailableVersions(); + + void setAvailableVersions( List<ArtifactVersion> versions ); + + boolean isOptional(); + + void setOptional( boolean optional ); + + ArtifactVersion getSelectedVersion() + throws OverConstrainedVersionException; + + boolean isSelectedVersionKnown() + throws OverConstrainedVersionException; + +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/ArtifactUtils.java b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/ArtifactUtils.java new file mode 100644 index 00000000..8efc45cd --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/ArtifactUtils.java @@ -0,0 +1,215 @@ +package org.apache.maven.artifact; + +/* + * 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. + */ + +import java.util.ArrayList; +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.regex.Matcher; + +import org.apache.maven.artifact.versioning.VersionRange; + +public final class ArtifactUtils +{ + + public static boolean isSnapshot( String version ) + { + if ( version != null ) + { + if ( version.regionMatches( true, version.length() - Artifact.SNAPSHOT_VERSION.length(), + Artifact.SNAPSHOT_VERSION, 0, Artifact.SNAPSHOT_VERSION.length() ) ) + { + return true; + } + else if ( Artifact.VERSION_FILE_PATTERN.matcher( version ).matches() ) + { + return true; + } + } + return false; + } + + public static String toSnapshotVersion( String version ) + { + if ( version == null ) + { + throw new IllegalArgumentException( "version: null" ); + } + + Matcher m = Artifact.VERSION_FILE_PATTERN.matcher( version ); + if ( m.matches() ) + { + return m.group( 1 ) + "-" + Artifact.SNAPSHOT_VERSION; + } + else + { + return version; + } + } + + public static String versionlessKey( Artifact artifact ) + { + return versionlessKey( artifact.getGroupId(), artifact.getArtifactId() ); + } + + public static String versionlessKey( String groupId, String artifactId ) + { + if ( groupId == null ) + { + throw new NullPointerException( "groupId is null" ); + } + if ( artifactId == null ) + { + throw new NullPointerException( "artifactId is null" ); + } + return groupId + ":" + artifactId; + } + + public static String key( Artifact artifact ) + { + return key( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion() ); + } + + public static String key( String groupId, String artifactId, String version ) + { + if ( groupId == null ) + { + throw new NullPointerException( "groupId is null" ); + } + if ( artifactId == null ) + { + throw new NullPointerException( "artifactId is null" ); + } + if ( version == null ) + { + throw new NullPointerException( "version is null" ); + } + + return groupId + ":" + artifactId + ":" + version; + } + + public static Map<String, Artifact> artifactMapByVersionlessId( Collection<Artifact> artifacts ) + { + Map<String, Artifact> artifactMap = new LinkedHashMap<String, Artifact>(); + + if ( artifacts != null ) + { + for ( Artifact artifact : artifacts ) + { + artifactMap.put( versionlessKey( artifact ), artifact ); + } + } + + return artifactMap; + } + + public static Artifact copyArtifactSafe( Artifact artifact ) + { + return ( artifact != null ) ? copyArtifact( artifact ) : null; + } + + public static Artifact copyArtifact( Artifact artifact ) + { + VersionRange range = artifact.getVersionRange(); + + // For some reason with the introduction of MNG-1577 we have the case in Yoko where a depMan section has + // something like the following: + // + // <dependencyManagement> + // <dependencies> + // <!-- Yoko modules --> + // <dependency> + // <groupId>org.apache.yoko</groupId> + // <artifactId>yoko-core</artifactId> + // <version>${version}</version> + // </dependency> + // ... + // + // And the range is not set so we'll check here and set it. jvz. + + if ( range == null ) + { + range = VersionRange.createFromVersion( artifact.getVersion() ); + } + + DefaultArtifact clone = new DefaultArtifact( artifact.getGroupId(), artifact.getArtifactId(), range.cloneOf(), + artifact.getScope(), artifact.getType(), artifact.getClassifier(), + artifact.getArtifactHandler(), artifact.isOptional() ); + clone.setRelease( artifact.isRelease() ); + clone.setResolvedVersion( artifact.getVersion() ); + clone.setResolved( artifact.isResolved() ); + clone.setFile( artifact.getFile() ); + + clone.setAvailableVersions( copyList( artifact.getAvailableVersions() ) ); + if ( artifact.getVersion() != null ) + { + clone.setBaseVersion( artifact.getBaseVersion() ); + } + clone.setDependencyFilter( artifact.getDependencyFilter() ); + clone.setDependencyTrail( copyList( artifact.getDependencyTrail() ) ); + clone.setDownloadUrl( artifact.getDownloadUrl() ); + clone.setRepository( artifact.getRepository() ); + + return clone; + } + + /** Returns <code>to</code> collection */ + public static <T extends Collection<Artifact>> T copyArtifacts( Collection<Artifact> from, T to ) + { + for ( Artifact artifact : from ) + { + to.add( ArtifactUtils.copyArtifact( artifact ) ); + } + return to; + } + + public static <K, T extends Map<K, Artifact>> T copyArtifacts( Map<K, ? extends Artifact> from, T to ) + { + if ( from != null ) + { + for ( Map.Entry<K, ? extends Artifact> entry : from.entrySet() ) + { + to.put( entry.getKey(), ArtifactUtils.copyArtifact( entry.getValue() ) ); + } + } + + return to; + } + + private static <T> List<T> copyList( List<T> original ) + { + List<T> copy = null; + + if ( original != null ) + { + copy = new ArrayList<T>(); + + if ( !original.isEmpty() ) + { + copy.addAll( original ); + } + } + + return copy; + } + +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/DefaultArtifact.java b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/DefaultArtifact.java new file mode 100644 index 00000000..e3e42c0a --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/DefaultArtifact.java @@ -0,0 +1,597 @@ +package org.apache.maven.artifact; + +/* + * 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. + */ + +import java.io.File; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.regex.Matcher; + +import org.apache.maven.artifact.handler.ArtifactHandler; +import org.apache.maven.artifact.metadata.ArtifactMetadata; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.resolver.filter.ArtifactFilter; +import org.apache.maven.artifact.versioning.ArtifactVersion; +import org.apache.maven.artifact.versioning.DefaultArtifactVersion; +import org.apache.maven.artifact.versioning.OverConstrainedVersionException; +import org.apache.maven.artifact.versioning.VersionRange; +import org.codehaus.plexus.util.StringUtils; + +/** + * @author Jason van Zyl + */ +public class DefaultArtifact + implements Artifact +{ + private String groupId; + + private String artifactId; + + private String baseVersion; + + private final String type; + + private final String classifier; + + private volatile String scope; + + private volatile File file; + + private ArtifactRepository repository; + + private String downloadUrl; + + private ArtifactFilter dependencyFilter; + + private ArtifactHandler artifactHandler; + + private List<String> dependencyTrail; + + private volatile String version; + + private VersionRange versionRange; + + private volatile boolean resolved; + + private boolean release; + + private List<ArtifactVersion> availableVersions; + + private Map<Object, ArtifactMetadata> metadataMap; + + private boolean optional; + + public DefaultArtifact( String groupId, String artifactId, String version, String scope, String type, + String classifier, ArtifactHandler artifactHandler ) + { + this( groupId, artifactId, VersionRange.createFromVersion( version ), scope, type, classifier, artifactHandler, + false ); + } + + public DefaultArtifact( String groupId, String artifactId, VersionRange versionRange, String scope, String type, + String classifier, ArtifactHandler artifactHandler ) + { + this( groupId, artifactId, versionRange, scope, type, classifier, artifactHandler, false ); + } + + public DefaultArtifact( String groupId, String artifactId, VersionRange versionRange, String scope, String type, + String classifier, ArtifactHandler artifactHandler, boolean optional ) + { + this.groupId = groupId; + + this.artifactId = artifactId; + + this.versionRange = versionRange; + + selectVersionFromNewRangeIfAvailable(); + + this.artifactHandler = artifactHandler; + + this.scope = scope; + + this.type = type; + + if ( classifier == null ) + { + classifier = artifactHandler.getClassifier(); + } + + this.classifier = classifier; + + this.optional = optional; + + validateIdentity(); + } + + private void validateIdentity() + { + if ( empty( groupId ) ) + { + throw new InvalidArtifactRTException( groupId, artifactId, getVersion(), type, + "The groupId cannot be empty." ); + } + + if ( artifactId == null ) + { + throw new InvalidArtifactRTException( groupId, artifactId, getVersion(), type, + "The artifactId cannot be empty." ); + } + + if ( type == null ) + { + throw new InvalidArtifactRTException( groupId, artifactId, getVersion(), type, + "The type cannot be empty." ); + } + + if ( ( version == null ) && ( versionRange == null ) ) + { + throw new InvalidArtifactRTException( groupId, artifactId, getVersion(), type, + "The version cannot be empty." ); + } + } + + private boolean empty( String value ) + { + return ( value == null ) || ( value.trim().length() < 1 ); + } + + public String getClassifier() + { + return classifier; + } + + public boolean hasClassifier() + { + return StringUtils.isNotEmpty( classifier ); + } + + public String getScope() + { + return scope; + } + + public String getGroupId() + { + return groupId; + } + + public String getArtifactId() + { + return artifactId; + } + + public String getVersion() + { + return version; + } + + public void setVersion( String version ) + { + this.version = version; + setBaseVersionInternal( version ); + versionRange = null; + } + + public String getType() + { + return type; + } + + public void setFile( File file ) + { + this.file = file; + } + + public File getFile() + { + return file; + } + + public ArtifactRepository getRepository() + { + return repository; + } + + public void setRepository( ArtifactRepository repository ) + { + this.repository = repository; + } + + // ---------------------------------------------------------------------- + // + // ---------------------------------------------------------------------- + + public String getId() + { + return getDependencyConflictId() + ":" + getBaseVersion(); + } + + public String getDependencyConflictId() + { + StringBuilder sb = new StringBuilder( 128 ); + sb.append( getGroupId() ); + sb.append( ":" ); + appendArtifactTypeClassifierString( sb ); + return sb.toString(); + } + + private void appendArtifactTypeClassifierString( StringBuilder sb ) + { + sb.append( getArtifactId() ); + sb.append( ":" ); + sb.append( getType() ); + if ( hasClassifier() ) + { + sb.append( ":" ); + sb.append( getClassifier() ); + } + } + + public void addMetadata( ArtifactMetadata metadata ) + { + if ( metadataMap == null ) + { + metadataMap = new HashMap<Object, ArtifactMetadata>(); + } + + ArtifactMetadata m = metadataMap.get( metadata.getKey() ); + if ( m != null ) + { + m.merge( metadata ); + } + else + { + metadataMap.put( metadata.getKey(), metadata ); + } + } + + public Collection<ArtifactMetadata> getMetadataList() + { + if ( metadataMap == null ) + { + return Collections.emptyList(); + } + + return metadataMap.values(); + } + + // ---------------------------------------------------------------------- + // Object overrides + // ---------------------------------------------------------------------- + + public String toString() + { + StringBuilder sb = new StringBuilder(); + if ( getGroupId() != null ) + { + sb.append( getGroupId() ); + sb.append( ":" ); + } + appendArtifactTypeClassifierString( sb ); + sb.append( ":" ); + if ( getBaseVersionInternal() != null ) + { + sb.append( getBaseVersionInternal() ); + } + else + { + sb.append( versionRange.toString() ); + } + if ( scope != null ) + { + sb.append( ":" ); + sb.append( scope ); + } + return sb.toString(); + } + + public int hashCode() + { + int result = 17; + result = 37 * result + groupId.hashCode(); + result = 37 * result + artifactId.hashCode(); + result = 37 * result + type.hashCode(); + if ( version != null ) + { + result = 37 * result + version.hashCode(); + } + result = 37 * result + ( classifier != null ? classifier.hashCode() : 0 ); + return result; + } + + public boolean equals( Object o ) + { + if ( o == this ) + { + return true; + } + + if ( !( o instanceof Artifact ) ) + { + return false; + } + + Artifact a = (Artifact) o; + + if ( !a.getGroupId().equals( groupId ) ) + { + return false; + } + else if ( !a.getArtifactId().equals( artifactId ) ) + { + return false; + } + else if ( !a.getVersion().equals( version ) ) + { + return false; + } + else if ( !a.getType().equals( type ) ) + { + return false; + } + else if ( a.getClassifier() == null ? classifier != null : !a.getClassifier().equals( classifier ) ) + { + return false; + } + + // We don't consider the version range in the comparison, just the resolved version + + return true; + } + + public String getBaseVersion() + { + if ( baseVersion == null && version != null ) + { + setBaseVersionInternal( version ); + } + + return baseVersion; + } + + protected String getBaseVersionInternal() + { + if ( ( baseVersion == null ) && ( version != null ) ) + { + setBaseVersionInternal( version ); + } + + return baseVersion; + } + + public void setBaseVersion( String baseVersion ) + { + setBaseVersionInternal( baseVersion ); + } + + protected void setBaseVersionInternal( String baseVersion ) + { + Matcher m = VERSION_FILE_PATTERN.matcher( baseVersion ); + + if ( m.matches() ) + { + this.baseVersion = m.group( 1 ) + "-" + SNAPSHOT_VERSION; + } + else + { + this.baseVersion = baseVersion; + } + } + + public int compareTo( Artifact a ) + { + int result = groupId.compareTo( a.getGroupId() ); + if ( result == 0 ) + { + result = artifactId.compareTo( a.getArtifactId() ); + if ( result == 0 ) + { + result = type.compareTo( a.getType() ); + if ( result == 0 ) + { + if ( classifier == null ) + { + if ( a.getClassifier() != null ) + { + result = 1; + } + } + else + { + if ( a.getClassifier() != null ) + { + result = classifier.compareTo( a.getClassifier() ); + } + else + { + result = -1; + } + } + if ( result == 0 ) + { + // We don't consider the version range in the comparison, just the resolved version + result = new DefaultArtifactVersion( version ).compareTo( + new DefaultArtifactVersion( a.getVersion() ) ); + } + } + } + } + return result; + } + + public void updateVersion( String version, ArtifactRepository localRepository ) + { + setResolvedVersion( version ); + setFile( new File( localRepository.getBasedir(), localRepository.pathOf( this ) ) ); + } + + public String getDownloadUrl() + { + return downloadUrl; + } + + public void setDownloadUrl( String downloadUrl ) + { + this.downloadUrl = downloadUrl; + } + + public ArtifactFilter getDependencyFilter() + { + return dependencyFilter; + } + + public void setDependencyFilter( ArtifactFilter artifactFilter ) + { + dependencyFilter = artifactFilter; + } + + public ArtifactHandler getArtifactHandler() + { + return artifactHandler; + } + + public List<String> getDependencyTrail() + { + return dependencyTrail; + } + + public void setDependencyTrail( List<String> dependencyTrail ) + { + this.dependencyTrail = dependencyTrail; + } + + public void setScope( String scope ) + { + this.scope = scope; + } + + public VersionRange getVersionRange() + { + return versionRange; + } + + public void setVersionRange( VersionRange versionRange ) + { + this.versionRange = versionRange; + selectVersionFromNewRangeIfAvailable(); + } + + private void selectVersionFromNewRangeIfAvailable() + { + if ( ( versionRange != null ) && ( versionRange.getRecommendedVersion() != null ) ) + { + selectVersion( versionRange.getRecommendedVersion().toString() ); + } + else + { + version = null; + baseVersion = null; + } + } + + public void selectVersion( String version ) + { + this.version = version; + setBaseVersionInternal( version ); + } + + public void setGroupId( String groupId ) + { + this.groupId = groupId; + } + + public void setArtifactId( String artifactId ) + { + this.artifactId = artifactId; + } + + public boolean isSnapshot() + { + return getBaseVersion() != null + && ( getBaseVersion().endsWith( SNAPSHOT_VERSION ) || getBaseVersion().equals( LATEST_VERSION ) ); + } + + public void setResolved( boolean resolved ) + { + this.resolved = resolved; + } + + public boolean isResolved() + { + return resolved; + } + + public void setResolvedVersion( String version ) + { + this.version = version; + // retain baseVersion + } + + public void setArtifactHandler( ArtifactHandler artifactHandler ) + { + this.artifactHandler = artifactHandler; + } + + public void setRelease( boolean release ) + { + this.release = release; + } + + public boolean isRelease() + { + return release; + } + + public List<ArtifactVersion> getAvailableVersions() + { + return availableVersions; + } + + public void setAvailableVersions( List<ArtifactVersion> availableVersions ) + { + this.availableVersions = availableVersions; + } + + public boolean isOptional() + { + return optional; + } + + public ArtifactVersion getSelectedVersion() + throws OverConstrainedVersionException + { + return versionRange.getSelectedVersion( this ); + } + + public boolean isSelectedVersionKnown() + throws OverConstrainedVersionException + { + return versionRange.isSelectedVersionKnown( this ); + } + + public void setOptional( boolean optional ) + { + this.optional = optional; + } + +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/InvalidArtifactRTException.java b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/InvalidArtifactRTException.java new file mode 100644 index 00000000..adf656d1 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/InvalidArtifactRTException.java @@ -0,0 +1,100 @@ +package org.apache.maven.artifact; + +/* + * 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. + */ + +/** + * Exception thrown when the identity of an artifact can not be established, + * eg. one of groupId, artifactId, version or type is null. + */ +public class InvalidArtifactRTException + extends RuntimeException +{ + + private final String groupId; + private final String artifactId; + private final String version; + private final String type; + private final String baseMessage; + + public InvalidArtifactRTException( String groupId, + String artifactId, + String version, + String type, + String message ) + { + this.groupId = groupId; + this.artifactId = artifactId; + this.version = version; + this.type = type; + this.baseMessage = message; + } + + public InvalidArtifactRTException( String groupId, + String artifactId, + String version, + String type, + String message, + Throwable cause ) + { + super( cause ); + + this.groupId = groupId; + this.artifactId = artifactId; + this.version = version; + this.type = type; + this.baseMessage = message; + } + + public String getMessage() + { + return "For artifact {" + getArtifactKey() + "}: " + getBaseMessage(); + } + + public String getBaseMessage() + { + return baseMessage; + } + + public String getArtifactId() + { + return artifactId; + } + + public String getGroupId() + { + return groupId; + } + + public String getType() + { + return type; + } + + public String getVersion() + { + return version; + } + + public String getArtifactKey() + { + return groupId + ":" + artifactId + ":" + version + ":" + type; + } + +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/handler/ArtifactHandler.java b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/handler/ArtifactHandler.java new file mode 100644 index 00000000..a9d60f2e --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/handler/ArtifactHandler.java @@ -0,0 +1,42 @@ +package org.apache.maven.artifact.handler; + +/* + * 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. + */ + +/** + * @author <a href="mailto:jason@maven.org">Jason van Zyl</a> + */ +public interface ArtifactHandler +{ + String ROLE = ArtifactHandler.class.getName(); + + String getExtension(); + + String getDirectory(); + + String getClassifier(); + + String getPackaging(); + + boolean isIncludesDependencies(); + + String getLanguage(); + + boolean isAddedToClasspath(); +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/ArtifactMetadata.java b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/ArtifactMetadata.java new file mode 100644 index 00000000..452c9f4a --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/ArtifactMetadata.java @@ -0,0 +1,27 @@ +package org.apache.maven.artifact.metadata; + +/* + * 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. + */ + +@Deprecated +public interface ArtifactMetadata + extends org.apache.maven.repository.legacy.metadata.ArtifactMetadata +{ + void merge( ArtifactMetadata metadata ); +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/repository/ArtifactRepository.java b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/repository/ArtifactRepository.java new file mode 100644 index 00000000..9ef30387 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/repository/ArtifactRepository.java @@ -0,0 +1,135 @@ +package org.apache.maven.artifact.repository; + +/* + * 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. + */ + +import java.util.List; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.metadata.ArtifactMetadata; +import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; +import org.apache.maven.repository.Proxy; + +/** + * Abstraction of an artifact repository. Artifact repositories can be remote, local, or even build reactor or + * IDE workspace. + */ +public interface ArtifactRepository +{ + String pathOf( Artifact artifact ); + + String pathOfRemoteRepositoryMetadata( ArtifactMetadata artifactMetadata ); + + String pathOfLocalRepositoryMetadata( ArtifactMetadata metadata, ArtifactRepository repository ); + + String getUrl(); + + void setUrl( String url ); + + String getBasedir(); + + String getProtocol(); + + String getId(); + + void setId( String id ); + + ArtifactRepositoryPolicy getSnapshots(); + + void setSnapshotUpdatePolicy( ArtifactRepositoryPolicy policy ); + + ArtifactRepositoryPolicy getReleases(); + + void setReleaseUpdatePolicy( ArtifactRepositoryPolicy policy ); + + ArtifactRepositoryLayout getLayout(); + + void setLayout( ArtifactRepositoryLayout layout ); + + String getKey(); + + @Deprecated + boolean isUniqueVersion(); + + @Deprecated + boolean isBlacklisted(); + + @Deprecated + void setBlacklisted( boolean blackListed ); + + // + // New interface methods for the repository system. + // + /** + * + * @param artifact + * @return + * @since 3.0-alpha-3 + */ + Artifact find( Artifact artifact ); + + /** + * Finds the versions of the specified artifact that are available in this repository. + * + * @param artifact The artifact whose available versions should be determined, must not be {@code null}. + * @return The available versions of the artifact or an empty list if none, never {@code null}. + * @since 3.0-alpha-3 + */ + List<String> findVersions( Artifact artifact ); + + /** + * Indicates whether this repository is backed by actual projects. For instance, the build reactor or IDE workspace + * are examples of such repositories. + * + * @return {@code true} if the repository is backed by actual projects, {@code false} otherwise. + * @since 3.0-beta-1 + */ + boolean isProjectAware(); + + /** + * @since 3.0-alpha-3 + */ + void setAuthentication( Authentication authentication ); + /** + * @since 3.0-alpha-3 + */ + Authentication getAuthentication(); + + /** + * @since 3.0-alpha-3 + */ + void setProxy( Proxy proxy ); + /** + * @since 3.0-alpha-3 + */ + Proxy getProxy(); + + /** + * @since 3.0.3 + * @return the repositories mirrored by the actual one + */ + List<ArtifactRepository> getMirroredRepositories(); + + /** + * @since 3.0.3 + * @param mirroredRepositories the repositories that the actual one mirrors + */ + void setMirroredRepositories( List<ArtifactRepository> mirroredRepositories ); + +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/repository/ArtifactRepositoryPolicy.java b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/repository/ArtifactRepositoryPolicy.java new file mode 100644 index 00000000..b6cd8f39 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/repository/ArtifactRepositoryPolicy.java @@ -0,0 +1,222 @@ +package org.apache.maven.artifact.repository; + +/* + * 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. + */ + +import java.util.Calendar; +import java.util.Date; + +/** + * Describes a set of policies for a repository to use under certain conditions. + * + * @author <a href="mailto:brett@apache.org">Brett Porter</a> + */ +public class ArtifactRepositoryPolicy +{ + public static final String UPDATE_POLICY_NEVER = "never"; + + public static final String UPDATE_POLICY_ALWAYS = "always"; + + public static final String UPDATE_POLICY_DAILY = "daily"; + + public static final String UPDATE_POLICY_INTERVAL = "interval"; + + public static final String CHECKSUM_POLICY_FAIL = "fail"; + + public static final String CHECKSUM_POLICY_WARN = "warn"; + + public static final String CHECKSUM_POLICY_IGNORE = "ignore"; + + private boolean enabled; + + private String updatePolicy; + + private String checksumPolicy; + + public ArtifactRepositoryPolicy() + { + this( true, null, null ); + } + + public ArtifactRepositoryPolicy( ArtifactRepositoryPolicy policy ) + { + this( policy.isEnabled(), policy.getUpdatePolicy(), policy.getChecksumPolicy() ); + } + + public ArtifactRepositoryPolicy( boolean enabled, String updatePolicy, String checksumPolicy ) + { + this.enabled = enabled; + + if ( updatePolicy == null ) + { + updatePolicy = UPDATE_POLICY_DAILY; + } + this.updatePolicy = updatePolicy; + + if ( checksumPolicy == null ) + { + checksumPolicy = CHECKSUM_POLICY_WARN; + } + this.checksumPolicy = checksumPolicy; + } + + public void setEnabled( boolean enabled ) + { + this.enabled = enabled; + } + + public void setUpdatePolicy( String updatePolicy ) + { + if ( updatePolicy != null ) + { + this.updatePolicy = updatePolicy; + } + } + + public void setChecksumPolicy( String checksumPolicy ) + { + if ( checksumPolicy != null ) + { + this.checksumPolicy = checksumPolicy; + } + } + + public boolean isEnabled() + { + return enabled; + } + + public String getUpdatePolicy() + { + return updatePolicy; + } + + public String getChecksumPolicy() + { + return checksumPolicy; + } + + public boolean checkOutOfDate( Date lastModified ) + { + boolean checkForUpdates = false; + + if ( UPDATE_POLICY_ALWAYS.equals( updatePolicy ) ) + { + checkForUpdates = true; + } + else if ( UPDATE_POLICY_DAILY.equals( updatePolicy ) ) + { + // Get local midnight boundary + Calendar cal = Calendar.getInstance(); + + cal.set( Calendar.HOUR_OF_DAY, 0 ); + cal.set( Calendar.MINUTE, 0 ); + cal.set( Calendar.SECOND, 0 ); + cal.set( Calendar.MILLISECOND, 0 ); + + if ( cal.getTime().after( lastModified ) ) + { + checkForUpdates = true; + } + } + else if ( updatePolicy.startsWith( UPDATE_POLICY_INTERVAL ) ) + { + String s = updatePolicy.substring( UPDATE_POLICY_INTERVAL.length() + 1 ); + int minutes = Integer.valueOf( s ); + Calendar cal = Calendar.getInstance(); + cal.add( Calendar.MINUTE, -minutes ); + if ( cal.getTime().after( lastModified ) ) + { + checkForUpdates = true; + } + } + // else assume "never" + return checkForUpdates; + } + + @Override + public String toString() + { + StringBuilder buffer = new StringBuilder( 64 ); + buffer.append( "{enabled=" ); + buffer.append( enabled ); + buffer.append( ", checksums=" ); + buffer.append( checksumPolicy ); + buffer.append( ", updates=" ); + buffer.append( updatePolicy ); + buffer.append( "}" ); + return buffer.toString(); + } + + public void merge( ArtifactRepositoryPolicy policy ) + { + if ( policy != null && policy.isEnabled() ) + { + setEnabled( true ); + + if ( ordinalOfCksumPolicy( policy.getChecksumPolicy() ) < ordinalOfCksumPolicy( getChecksumPolicy() ) ) + { + setChecksumPolicy( policy.getChecksumPolicy() ); + } + + if ( ordinalOfUpdatePolicy( policy.getUpdatePolicy() ) < ordinalOfUpdatePolicy( getUpdatePolicy() ) ) + { + setUpdatePolicy( policy.getUpdatePolicy() ); + } + } + } + + private int ordinalOfCksumPolicy( String policy ) + { + if ( ArtifactRepositoryPolicy.CHECKSUM_POLICY_FAIL.equals( policy ) ) + { + return 2; + } + else if ( ArtifactRepositoryPolicy.CHECKSUM_POLICY_IGNORE.equals( policy ) ) + { + return 0; + } + else + { + return 1; + } + } + + private int ordinalOfUpdatePolicy( String policy ) + { + if ( ArtifactRepositoryPolicy.UPDATE_POLICY_DAILY.equals( policy ) ) + { + return 1440; + } + else if ( ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS.equals( policy ) ) + { + return 0; + } + else if ( policy != null && policy.startsWith( ArtifactRepositoryPolicy.UPDATE_POLICY_INTERVAL ) ) + { + String s = policy.substring( UPDATE_POLICY_INTERVAL.length() + 1 ); + return Integer.valueOf( s ); + } + else + { + return Integer.MAX_VALUE; + } + } + +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/repository/Authentication.java b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/repository/Authentication.java new file mode 100644 index 00000000..323fb25b --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/repository/Authentication.java @@ -0,0 +1,126 @@ +package org.apache.maven.artifact.repository; + +/* + * 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. + */ + +public class Authentication +{ + + private String privateKey; + + private String passphrase; + + public Authentication( String userName, String password ) + { + this.username = userName; + this.password = password; + } + + /** + * Username used to login to the host + */ + private String username; + + /** + * Password associated with the login + */ + private String password; + + /** + * Get the user's password which is used when connecting to the repository. + * + * @return password of user + */ + public String getPassword() + { + return password; + } + + /** + * Set the user's password which is used when connecting to the repository. + * + * @param password password of the user + */ + public void setPassword( String password ) + { + this.password = password; + } + + /** + * Get the username used to access the repository. + * + * @return username at repository + */ + public String getUsername() + { + return username; + } + + /** + * Set username used to access the repository. + * + * @param userName the username used to access repository + */ + public void setUsername( final String userName ) + { + this.username = userName; + } + + /** + * Get the passphrase of the private key file. The passphrase is used only when host/protocol supports + * authentication via exchange of private/public keys and private key was used for authentication. + * + * @return passphrase of the private key file + */ + public String getPassphrase() + { + return passphrase; + } + + /** + * Set the passphrase of the private key file. + * + * @param passphrase passphrase of the private key file + */ + public void setPassphrase( final String passphrase ) + { + this.passphrase = passphrase; + } + + /** + * Get the absolute path to the private key file. + * + * @return absolute path to private key + */ + public String getPrivateKey() + { + return privateKey; + } + + /** + * Set the absolute path to private key file. + * + * @param privateKey path to private key in local file system + */ + public void setPrivateKey( final String privateKey ) + { + this.privateKey = privateKey; + } + +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/ArtifactRepositoryLayout.java b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/ArtifactRepositoryLayout.java new file mode 100644 index 00000000..2a18c863 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/ArtifactRepositoryLayout.java @@ -0,0 +1,38 @@ +package org.apache.maven.artifact.repository.layout; + +/* + * 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. + */ + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.metadata.ArtifactMetadata; +import org.apache.maven.artifact.repository.ArtifactRepository; + +/** @author jdcasey */ +public interface ArtifactRepositoryLayout +{ + String ROLE = ArtifactRepositoryLayout.class.getName(); + + String getId(); + + String pathOf( Artifact artifact ); + + String pathOfLocalRepositoryMetadata( ArtifactMetadata metadata, ArtifactRepository repository ); + + String pathOfRemoteRepositoryMetadata( ArtifactMetadata metadata ); +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/ArtifactRepositoryLayout2.java b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/ArtifactRepositoryLayout2.java new file mode 100644 index 00000000..c0544e5c --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/repository/layout/ArtifactRepositoryLayout2.java @@ -0,0 +1,31 @@ +package org.apache.maven.artifact.repository.layout; + +/* + * 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. + */ + +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; + +public interface ArtifactRepositoryLayout2 + extends ArtifactRepositoryLayout +{ + + ArtifactRepository newMavenArtifactRepository( String id, String url, ArtifactRepositoryPolicy snapshots, + ArtifactRepositoryPolicy releases ); +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/repository/metadata/RepositoryMetadataStoreException.java b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/repository/metadata/RepositoryMetadataStoreException.java new file mode 100644 index 00000000..38488522 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/repository/metadata/RepositoryMetadataStoreException.java @@ -0,0 +1,40 @@ +package org.apache.maven.artifact.repository.metadata; + +/* + * 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. + */ + +/** + * Problem storing the repository metadata in the local repository. + * + * @author <a href="mailto:brett@apache.org">Brett Porter</a> + */ +public class RepositoryMetadataStoreException + extends Exception +{ + public RepositoryMetadataStoreException( String message ) + { + super( message ); + } + + public RepositoryMetadataStoreException( String message, + Exception e ) + { + super( message, e ); + } +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/AbstractArtifactResolutionException.java b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/AbstractArtifactResolutionException.java new file mode 100644 index 00000000..66e147c2 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/AbstractArtifactResolutionException.java @@ -0,0 +1,347 @@ +package org.apache.maven.artifact.resolver; + +/* + * 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. + */ + +import java.util.Iterator; +import java.util.List; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; + +/** + * Base class for artifact resolution exceptions. + * + * @author <a href="mailto:brett@apache.org">Brett Porter</a> + */ +public class AbstractArtifactResolutionException + extends Exception +{ + private String groupId; + + private String artifactId; + + private String version; + + private String type; + + private String classifier; + + private Artifact artifact; + + private List<ArtifactRepository> remoteRepositories; + + private final String originalMessage; + + private final String path; + + static final String LS = System.getProperty( "line.separator" ); + + @SuppressWarnings( "checkstyle:parameternumber" ) + protected AbstractArtifactResolutionException( String message, + String groupId, + String artifactId, + String version, + String type, + String classifier, + List<ArtifactRepository> remoteRepositories, + List<String> path ) + { + this( message, groupId, artifactId, version, type, classifier, remoteRepositories, path, null ); + } + + @SuppressWarnings( "checkstyle:parameternumber" ) + protected AbstractArtifactResolutionException( String message, + String groupId, + String artifactId, + String version, + String type, + String classifier, + List<ArtifactRepository> remoteRepositories, + List<String> path, + Throwable t ) + { + super( constructMessageBase( message, groupId, artifactId, version, type, remoteRepositories, path ), t ); + + this.originalMessage = message; + this.groupId = groupId; + this.artifactId = artifactId; + this.type = type; + this.classifier = classifier; + this.version = version; + this.remoteRepositories = remoteRepositories; + this.path = constructArtifactPath( path, "" ); + } + + protected AbstractArtifactResolutionException( String message, + Artifact artifact ) + { + this( message, artifact, null ); + } + + protected AbstractArtifactResolutionException( String message, + Artifact artifact, + List<ArtifactRepository> remoteRepositories ) + { + this( message, artifact, remoteRepositories, null ); + } + + protected AbstractArtifactResolutionException( String message, + Artifact artifact, + List<ArtifactRepository> remoteRepositories, + Throwable t ) + { + this( message, artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getType(), + artifact.getClassifier(), remoteRepositories, artifact.getDependencyTrail(), t ); + this.artifact = artifact; + } + + public Artifact getArtifact() + { + return artifact; + } + + public String getGroupId() + { + return groupId; + } + + public String getArtifactId() + { + return artifactId; + } + + public String getVersion() + { + return version; + } + + public String getType() + { + return type; + } + + /** @return the classifier */ + public String getClassifier() + { + return this.classifier; + } + + /** @return the path */ + public String getPath() + { + return this.path; + } + + public List<ArtifactRepository> getRemoteRepositories() + { + return remoteRepositories; + } + + public String getOriginalMessage() + { + return originalMessage; + } + + protected static String constructArtifactPath( List<String> path, + String indentation ) + { + StringBuilder sb = new StringBuilder(); + + if ( path != null ) + { + sb.append( LS ); + sb.append( indentation ); + sb.append( "Path to dependency: " ); + sb.append( LS ); + int num = 1; + for ( Iterator<String> i = path.iterator(); i.hasNext(); num++ ) + { + sb.append( indentation ); + sb.append( "\t" ); + sb.append( num ); + sb.append( ") " ); + sb.append( i.next() ); + sb.append( LS ); + } + } + + return sb.toString(); + } + + private static String constructMessageBase( String message, + String groupId, + String artifactId, + String version, + String type, + List<ArtifactRepository> remoteRepositories, + List<String> path ) + { + StringBuilder sb = new StringBuilder(); + + sb.append( message ); + + if ( message == null || !message.contains( "from the specified remote repositories:" ) ) + { + sb.append( LS ); + sb.append( " " ).append( groupId ).append( ":" ).append( artifactId ).append( ":" ).append( type ).append( + ":" ).append( version ); + sb.append( LS ); + if ( remoteRepositories != null ) + { + sb.append( LS ); + sb.append( "from the specified remote repositories:" ); + sb.append( LS ).append( " " ); + + if ( remoteRepositories.isEmpty() ) + { + sb.append( "(none)" ); + } + + for ( Iterator<ArtifactRepository> i = remoteRepositories.iterator(); i.hasNext(); ) + { + ArtifactRepository remoteRepository = i.next(); + + sb.append( remoteRepository.getId() ); + sb.append( " (" ); + sb.append( remoteRepository.getUrl() ); + + ArtifactRepositoryPolicy releases = remoteRepository.getReleases(); + if ( releases != null ) + { + sb.append( ", releases=" ).append( releases.isEnabled() ); + } + + ArtifactRepositoryPolicy snapshots = remoteRepository.getSnapshots(); + if ( snapshots != null ) + { + sb.append( ", snapshots=" ).append( snapshots.isEnabled() ); + } + + sb.append( ")" ); + if ( i.hasNext() ) + { + sb.append( "," ).append( LS ).append( " " ); + } + } + } + + sb.append( constructArtifactPath( path, "" ) ); + sb.append( LS ); + } + + return sb.toString(); + } + + @SuppressWarnings( "checkstyle:parameternumber" ) + protected static String constructMissingArtifactMessage( String message, + String indentation, + String groupId, + String artifactId, + String version, + String type, + String classifier, + String downloadUrl, + List<String> path ) + { + StringBuilder sb = new StringBuilder( message ); + + if ( !"pom".equals( type ) ) + { + if ( downloadUrl != null ) + { + sb.append( LS ); + sb.append( LS ); + sb.append( indentation ); + sb.append( "Try downloading the file manually from: " ); + sb.append( LS ); + sb.append( indentation ); + sb.append( " " ); + sb.append( downloadUrl ); + } + else + { + sb.append( LS ); + sb.append( LS ); + sb.append( indentation ); + sb.append( "Try downloading the file manually from the project website." ); + } + + sb.append( LS ); + sb.append( LS ); + sb.append( indentation ); + sb.append( "Then, install it using the command: " ); + sb.append( LS ); + sb.append( indentation ); + sb.append( " mvn install:install-file -DgroupId=" ); + sb.append( groupId ); + sb.append( " -DartifactId=" ); + sb.append( artifactId ); + sb.append( " -Dversion=" ); + sb.append( version ); + + //insert classifier only if it was used in the artifact + if ( classifier != null && !classifier.equals( "" ) ) + { + sb.append( " -Dclassifier=" ); + sb.append( classifier ); + } + sb.append( " -Dpackaging=" ); + sb.append( type ); + sb.append( " -Dfile=/path/to/file" ); + sb.append( LS ); + + // If people want to deploy it + sb.append( LS ); + sb.append( indentation ); + sb.append( "Alternatively, if you host your own repository you can deploy the file there: " ); + sb.append( LS ); + sb.append( indentation ); + sb.append( " mvn deploy:deploy-file -DgroupId=" ); + sb.append( groupId ); + sb.append( " -DartifactId=" ); + sb.append( artifactId ); + sb.append( " -Dversion=" ); + sb.append( version ); + + //insert classifier only if it was used in the artifact + if ( classifier != null && !classifier.equals( "" ) ) + { + sb.append( " -Dclassifier=" ); + sb.append( classifier ); + } + sb.append( " -Dpackaging=" ); + sb.append( type ); + sb.append( " -Dfile=/path/to/file" ); + sb.append( " -Durl=[url] -DrepositoryId=[id]" ); + sb.append( LS ); + } + + sb.append( constructArtifactPath( path, indentation ) ); + sb.append( LS ); + + return sb.toString(); + } + + public String getArtifactPath() + { + return path; + } +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/ArtifactNotFoundException.java b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/ArtifactNotFoundException.java new file mode 100644 index 00000000..76f7b584 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/ArtifactNotFoundException.java @@ -0,0 +1,85 @@ +package org.apache.maven.artifact.resolver; + +/* + * 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. + */ + + +import java.util.List; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.repository.ArtifactRepository; + +/** + * @author Jason van Zyl + */ +public class ArtifactNotFoundException + extends AbstractArtifactResolutionException +{ + private String downloadUrl; + + protected ArtifactNotFoundException( String message, Artifact artifact, + List<ArtifactRepository> remoteRepositories ) + { + super( message, artifact, remoteRepositories ); + } + + public ArtifactNotFoundException( String message, Artifact artifact ) + { + this( message, artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getType(), + artifact.getClassifier(), null, artifact.getDownloadUrl(), artifact.getDependencyTrail() ); + } + + protected ArtifactNotFoundException( String message, Artifact artifact, + List<ArtifactRepository> remoteRepositories, Throwable cause ) + { + this( message, artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getType(), + artifact.getClassifier(), remoteRepositories, artifact.getDownloadUrl(), artifact.getDependencyTrail(), + cause ); + } + + @SuppressWarnings( "checkstyle:parameternumber" ) + public ArtifactNotFoundException( String message, String groupId, String artifactId, String version, String type, + String classifier, List<ArtifactRepository> remoteRepositories, + String downloadUrl, List<String> path, Throwable cause ) + { + super( constructMissingArtifactMessage( message, "", groupId, artifactId, version, type, classifier, + downloadUrl, path ), groupId, artifactId, version, type, classifier, + remoteRepositories, null, cause ); + + this.downloadUrl = downloadUrl; + } + + @SuppressWarnings( "checkstyle:parameternumber" ) + private ArtifactNotFoundException( String message, String groupId, String artifactId, String version, String type, + String classifier, List<ArtifactRepository> remoteRepositories, + String downloadUrl, List<String> path ) + { + super( constructMissingArtifactMessage( message, "", groupId, artifactId, version, type, classifier, + downloadUrl, path ), groupId, artifactId, version, type, classifier, + remoteRepositories, null ); + + this.downloadUrl = downloadUrl; + } + + public String getDownloadUrl() + { + return downloadUrl; + } + +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolutionException.java b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolutionException.java new file mode 100644 index 00000000..074d812c --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolutionException.java @@ -0,0 +1,68 @@ +package org.apache.maven.artifact.resolver; + +/* + * 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. + */ + +import java.util.List; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.repository.ArtifactRepository; + +/** + * @author Jason van Zyl + */ +public class ArtifactResolutionException + extends AbstractArtifactResolutionException +{ + @SuppressWarnings( "checkstyle:parameternumber" ) + public ArtifactResolutionException( String message, String groupId, String artifactId, String version, String type, + String classifier, List<ArtifactRepository> remoteRepositories, + List<String> path, Throwable t ) + { + super( message, groupId, artifactId, version, type, classifier, remoteRepositories, path, t ); + } + + public ArtifactResolutionException( String message, String groupId, String artifactId, String version, String type, + String classifier, Throwable t ) + { + super( message, groupId, artifactId, version, type, classifier, null, null, t ); + } + + public ArtifactResolutionException( String message, Artifact artifact ) + { + super( message, artifact ); + } + + public ArtifactResolutionException( String message, Artifact artifact, List<ArtifactRepository> remoteRepositories ) + { + super( message, artifact, remoteRepositories ); + } + + public ArtifactResolutionException( String message, Artifact artifact, Throwable cause ) + { + super( message, artifact, null, cause ); + } + + public ArtifactResolutionException( String message, Artifact artifact, List<ArtifactRepository> remoteRepositories, + Throwable cause ) + { + super( message, artifact, remoteRepositories, cause ); + } + +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/CyclicDependencyException.java b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/CyclicDependencyException.java new file mode 100644 index 00000000..d3706179 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/CyclicDependencyException.java @@ -0,0 +1,45 @@ +package org.apache.maven.artifact.resolver; + +/* + * 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. + */ + +import org.apache.maven.artifact.Artifact; + +/** + * Indiciates a cycle in the dependency graph. + * + * @author <a href="mailto:brett@apache.org">Brett Porter</a> + */ +public class CyclicDependencyException + extends ArtifactResolutionException +{ + private Artifact artifact; + + public CyclicDependencyException( String message, + Artifact artifact ) + { + super( message, artifact ); + this.artifact = artifact; + } + + public Artifact getArtifact() + { + return artifact; + } +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/MultipleArtifactsNotFoundException.java b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/MultipleArtifactsNotFoundException.java new file mode 100644 index 00000000..0f13db15 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/MultipleArtifactsNotFoundException.java @@ -0,0 +1,122 @@ +package org.apache.maven.artifact.resolver; + +/* + * 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. + */ + +import java.util.ArrayList; +import java.util.List; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.repository.ArtifactRepository; + +/** + * Exception caused when one or more artifacts can not be resolved because they are not found in the + * local or remote repositories. + */ +public class MultipleArtifactsNotFoundException + extends ArtifactResolutionException +{ + private final List<Artifact> resolvedArtifacts; + private final List<Artifact> missingArtifacts; + + /** @deprecated use {@link #MultipleArtifactsNotFoundException(Artifact, List, List, List)} */ + @Deprecated + public MultipleArtifactsNotFoundException( Artifact originatingArtifact, + List<Artifact> missingArtifacts, + List<ArtifactRepository> remoteRepositories ) + { + this( originatingArtifact, new ArrayList<Artifact>(), missingArtifacts, remoteRepositories ); + } + + /** + * Create an instance of the exception with allrequired information. + * + * @param originatingArtifact the artifact that was being resolved + * @param resolvedArtifacts artifacts that could be resolved + * @param missingArtifacts artifacts that could not be resolved + * @param remoteRepositories remote repositories where the missing artifacts were not found + */ + public MultipleArtifactsNotFoundException( Artifact originatingArtifact, + List<Artifact> resolvedArtifacts, + List<Artifact> missingArtifacts, + List<ArtifactRepository> remoteRepositories ) + { + super( constructMessage( missingArtifacts ), originatingArtifact, remoteRepositories ); + this.resolvedArtifacts = resolvedArtifacts; + this.missingArtifacts = missingArtifacts; + } + + /** + * artifacts that could be resolved + * + * @return {@link List} of {@link Artifact} + */ + public List<Artifact> getResolvedArtifacts() + { + return resolvedArtifacts; + } + + /** + * artifacts that could NOT be resolved + * + * @return {@link List} of {@link Artifact} + */ + public List<Artifact> getMissingArtifacts() + { + return missingArtifacts; + } + + private static String constructMessage( List<Artifact> artifacts ) + { + StringBuilder buffer = new StringBuilder( "Missing:\n" ); + + buffer.append( "----------\n" ); + + int counter = 0; + + for ( Artifact artifact : artifacts ) + { + String message = ( ++counter ) + ") " + artifact.getId(); + + buffer.append( constructMissingArtifactMessage( message, " ", artifact.getGroupId(), + artifact.getArtifactId(), artifact.getVersion(), artifact.getType(), artifact.getClassifier(), + artifact.getDownloadUrl(), artifact.getDependencyTrail() ) ); + } + + buffer.append( "----------\n" ); + + int size = artifacts.size(); + + buffer.append( size ).append( " required artifact" ); + + if ( size > 1 ) + { + buffer.append( "s are" ); + } + else + { + buffer.append( " is" ); + } + + buffer.append( " missing.\n\nfor artifact: " ); + + return buffer.toString(); + } + +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/filter/ArtifactFilter.java b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/filter/ArtifactFilter.java new file mode 100644 index 00000000..27b08a88 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/filter/ArtifactFilter.java @@ -0,0 +1,30 @@ +package org.apache.maven.artifact.resolver.filter; + +/* + * 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. + */ + +import org.apache.maven.artifact.Artifact; + +/** + * @author <a href="mailto:jason@maven.org">Jason van Zyl</a> + */ +public interface ArtifactFilter +{ + boolean include( Artifact artifact ); +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/ArtifactVersion.java b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/ArtifactVersion.java new file mode 100644 index 00000000..5b516a91 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/ArtifactVersion.java @@ -0,0 +1,42 @@ +package org.apache.maven.artifact.versioning; + +/* + * 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. + */ + +/** + * Describes an artifact version in terms of its components, converts it to/from a string and + * compares two versions. + * + * @author <a href="mailto:brett@apache.org">Brett Porter</a> + */ +public interface ArtifactVersion + extends Comparable<ArtifactVersion> +{ + int getMajorVersion(); + + int getMinorVersion(); + + int getIncrementalVersion(); + + int getBuildNumber(); + + String getQualifier(); + + void parseVersion( String version ); +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/ComparableVersion.java b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/ComparableVersion.java new file mode 100644 index 00000000..67a46960 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/ComparableVersion.java @@ -0,0 +1,503 @@ +package org.apache.maven.artifact.versioning; + +/* + * 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. + */ + +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; +import java.util.Locale; +import java.util.Properties; +import java.util.Stack; + +/** + * Generic implementation of version comparison. + * + * <p>Features: + * <ul> + * <li>mixing of '<code>-</code>' (dash) and '<code>.</code>' (dot) separators,</li> + * <li>transition between characters and digits also constitutes a separator: + * <code>1.0alpha1 => [1, 0, alpha, 1]</code></li> + * <li>unlimited number of version components,</li> + * <li>version components in the text can be digits or strings,</li> + * <li>strings are checked for well-known qualifiers and the qualifier ordering is used for version ordering. + * Well-known qualifiers (case insensitive) are:<ul> + * <li><code>alpha</code> or <code>a</code></li> + * <li><code>beta</code> or <code>b</code></li> + * <li><code>milestone</code> or <code>m</code></li> + * <li><code>rc</code> or <code>cr</code></li> + * <li><code>snapshot</code></li> + * <li><code>(the empty string)</code> or <code>ga</code> or <code>final</code></li> + * <li><code>sp</code></li> + * </ul> + * Unknown qualifiers are considered after known qualifiers, with lexical order (always case insensitive), + * </li> + * <li>a dash usually precedes a qualifier, and is always less important than something preceded with a dot.</li> + * </ul></p> + * + * @see <a href="https://cwiki.apache.org/confluence/display/MAVENOLD/Versioning">"Versioning" on Maven Wiki</a> + * @author <a href="mailto:kenney@apache.org">Kenney Westerhof</a> + * @author <a href="mailto:hboutemy@apache.org">Hervé Boutemy</a> + */ +public class ComparableVersion + implements Comparable<ComparableVersion> +{ + private String value; + + private String canonical; + + private ListItem items; + + private interface Item + { + int INTEGER_ITEM = 0; + int STRING_ITEM = 1; + int LIST_ITEM = 2; + + int compareTo( Item item ); + + int getType(); + + boolean isNull(); + } + + /** + * Represents a numeric item in the version item list. + */ + private static class IntegerItem + implements Item + { + private static final BigInteger BIG_INTEGER_ZERO = new BigInteger( "0" ); + + private final BigInteger value; + + public static final IntegerItem ZERO = new IntegerItem(); + + private IntegerItem() + { + this.value = BIG_INTEGER_ZERO; + } + + public IntegerItem( String str ) + { + this.value = new BigInteger( str ); + } + + public int getType() + { + return INTEGER_ITEM; + } + + public boolean isNull() + { + return BIG_INTEGER_ZERO.equals( value ); + } + + public int compareTo( Item item ) + { + if ( item == null ) + { + return BIG_INTEGER_ZERO.equals( value ) ? 0 : 1; // 1.0 == 1, 1.1 > 1 + } + + switch ( item.getType() ) + { + case INTEGER_ITEM: + return value.compareTo( ( (IntegerItem) item ).value ); + + case STRING_ITEM: + return 1; // 1.1 > 1-sp + + case LIST_ITEM: + return 1; // 1.1 > 1-1 + + default: + throw new RuntimeException( "invalid item: " + item.getClass() ); + } + } + + public String toString() + { + return value.toString(); + } + } + + /** + * Represents a string in the version item list, usually a qualifier. + */ + private static class StringItem + implements Item + { + private static final String[] QUALIFIERS = { "alpha", "beta", "milestone", "rc", "snapshot", "", "sp" }; + + @SuppressWarnings( "checkstyle:constantname" ) + private static final List<String> _QUALIFIERS = Arrays.asList( QUALIFIERS ); + + private static final Properties ALIASES = new Properties(); + static + { + ALIASES.put( "ga", "" ); + ALIASES.put( "final", "" ); + ALIASES.put( "cr", "rc" ); + } + + /** + * A comparable value for the empty-string qualifier. This one is used to determine if a given qualifier makes + * the version older than one without a qualifier, or more recent. + */ + private static final String RELEASE_VERSION_INDEX = String.valueOf( _QUALIFIERS.indexOf( "" ) ); + + private String value; + + public StringItem( String value, boolean followedByDigit ) + { + if ( followedByDigit && value.length() == 1 ) + { + // a1 = alpha-1, b1 = beta-1, m1 = milestone-1 + switch ( value.charAt( 0 ) ) + { + case 'a': + value = "alpha"; + break; + case 'b': + value = "beta"; + break; + case 'm': + value = "milestone"; + break; + default: + } + } + this.value = ALIASES.getProperty( value , value ); + } + + public int getType() + { + return STRING_ITEM; + } + + public boolean isNull() + { + return ( comparableQualifier( value ).compareTo( RELEASE_VERSION_INDEX ) == 0 ); + } + + /** + * Returns a comparable value for a qualifier. + * + * This method takes into account the ordering of known qualifiers then unknown qualifiers with lexical + * ordering. + * + * just returning an Integer with the index here is faster, but requires a lot of if/then/else to check for -1 + * or QUALIFIERS.size and then resort to lexical ordering. Most comparisons are decided by the first character, + * so this is still fast. If more characters are needed then it requires a lexical sort anyway. + * + * @param qualifier + * @return an equivalent value that can be used with lexical comparison + */ + public static String comparableQualifier( String qualifier ) + { + int i = _QUALIFIERS.indexOf( qualifier ); + + return i == -1 ? ( _QUALIFIERS.size() + "-" + qualifier ) : String.valueOf( i ); + } + + public int compareTo( Item item ) + { + if ( item == null ) + { + // 1-rc < 1, 1-ga > 1 + return comparableQualifier( value ).compareTo( RELEASE_VERSION_INDEX ); + } + switch ( item.getType() ) + { + case INTEGER_ITEM: + return -1; // 1.any < 1.1 ? + + case STRING_ITEM: + return comparableQualifier( value ).compareTo( comparableQualifier( ( (StringItem) item ).value ) ); + + case LIST_ITEM: + return -1; // 1.any < 1-1 + + default: + throw new RuntimeException( "invalid item: " + item.getClass() ); + } + } + + public String toString() + { + return value; + } + } + + /** + * Represents a version list item. This class is used both for the global item list and for sub-lists (which start + * with '-(number)' in the version specification). + */ + private static class ListItem + extends ArrayList<Item> + implements Item + { + public int getType() + { + return LIST_ITEM; + } + + public boolean isNull() + { + return ( size() == 0 ); + } + + void normalize() + { + for ( int i = size() - 1; i >= 0; i-- ) + { + Item lastItem = get( i ); + + if ( lastItem.isNull() ) + { + // remove null trailing items: 0, "", empty list + remove( i ); + } + else if ( !( lastItem instanceof ListItem ) ) + { + break; + } + } + } + + public int compareTo( Item item ) + { + if ( item == null ) + { + if ( size() == 0 ) + { + return 0; // 1-0 = 1- (normalize) = 1 + } + Item first = get( 0 ); + return first.compareTo( null ); + } + switch ( item.getType() ) + { + case INTEGER_ITEM: + return -1; // 1-1 < 1.0.x + + case STRING_ITEM: + return 1; // 1-1 > 1-sp + + case LIST_ITEM: + Iterator<Item> left = iterator(); + Iterator<Item> right = ( (ListItem) item ).iterator(); + + while ( left.hasNext() || right.hasNext() ) + { + Item l = left.hasNext() ? left.next() : null; + Item r = right.hasNext() ? right.next() : null; + + // if this is shorter, then invert the compare and mul with -1 + int result = l == null ? ( r == null ? 0 : -1 * r.compareTo( l ) ) : l.compareTo( r ); + + if ( result != 0 ) + { + return result; + } + } + + return 0; + + default: + throw new RuntimeException( "invalid item: " + item.getClass() ); + } + } + + public String toString() + { + StringBuilder buffer = new StringBuilder(); + for ( Iterator<Item> iter = iterator(); iter.hasNext(); ) + { + Item item = iter.next(); + if ( buffer.length() > 0 ) + { + buffer.append( ( item instanceof ListItem ) ? '-' : '.' ); + } + buffer.append( item ); + } + return buffer.toString(); + } + } + + public ComparableVersion( String version ) + { + parseVersion( version ); + } + + public final void parseVersion( String version ) + { + this.value = version; + + items = new ListItem(); + + version = version.toLowerCase( Locale.ENGLISH ); + + ListItem list = items; + + Stack<Item> stack = new Stack<Item>(); + stack.push( list ); + + boolean isDigit = false; + + int startIndex = 0; + + for ( int i = 0; i < version.length(); i++ ) + { + char c = version.charAt( i ); + + if ( c == '.' ) + { + if ( i == startIndex ) + { + list.add( IntegerItem.ZERO ); + } + else + { + list.add( parseItem( isDigit, version.substring( startIndex, i ) ) ); + } + startIndex = i + 1; + } + else if ( c == '-' ) + { + if ( i == startIndex ) + { + list.add( IntegerItem.ZERO ); + } + else + { + list.add( parseItem( isDigit, version.substring( startIndex, i ) ) ); + } + startIndex = i + 1; + + list.add( list = new ListItem() ); + stack.push( list ); + } + else if ( Character.isDigit( c ) ) + { + if ( !isDigit && i > startIndex ) + { + list.add( new StringItem( version.substring( startIndex, i ), true ) ); + startIndex = i; + + list.add( list = new ListItem() ); + stack.push( list ); + } + + isDigit = true; + } + else + { + if ( isDigit && i > startIndex ) + { + list.add( parseItem( true, version.substring( startIndex, i ) ) ); + startIndex = i; + + list.add( list = new ListItem() ); + stack.push( list ); + } + + isDigit = false; + } + } + + if ( version.length() > startIndex ) + { + list.add( parseItem( isDigit, version.substring( startIndex ) ) ); + } + + while ( !stack.isEmpty() ) + { + list = (ListItem) stack.pop(); + list.normalize(); + } + + canonical = items.toString(); + } + + private static Item parseItem( boolean isDigit, String buf ) + { + return isDigit ? new IntegerItem( buf ) : new StringItem( buf, false ); + } + + public int compareTo( ComparableVersion o ) + { + return items.compareTo( o.items ); + } + + public String toString() + { + return value; + } + + public String getCanonical() + { + return canonical; + } + + public boolean equals( Object o ) + { + return ( o instanceof ComparableVersion ) && canonical.equals( ( (ComparableVersion) o ).canonical ); + } + + public int hashCode() + { + return canonical.hashCode(); + } + + /** + * Main to test version parsing and comparison. + * + * @param args the version strings to parse and compare + */ + public static void main( String... args ) + { + System.out.println( "Display parameters as parsed by Maven (in canonical form) and comparison result:" ); + if ( args.length == 0 ) + { + return; + } + + ComparableVersion prev = null; + int i = 1; + for ( String version : args ) + { + ComparableVersion c = new ComparableVersion( version ); + + if ( prev != null ) + { + int compare = prev.compareTo( c ); + System.out.println( " " + prev.toString() + ' ' + + ( ( compare == 0 ) ? "==" : ( ( compare < 0 ) ? "<" : ">" ) ) + ' ' + version ); + } + + System.out.println( String.valueOf( i++ ) + ". " + version + " == " + c.getCanonical() ); + + prev = c; + } + } +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/DefaultArtifactVersion.java b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/DefaultArtifactVersion.java new file mode 100644 index 00000000..99b2b85b --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/DefaultArtifactVersion.java @@ -0,0 +1,228 @@ +package org.apache.maven.artifact.versioning; + +/* + * 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. + */ + +import java.util.StringTokenizer; +import java.util.regex.Pattern; +import java.util.NoSuchElementException; + +/** + * Default implementation of artifact versioning. + * + * @author <a href="mailto:brett@apache.org">Brett Porter</a> + */ +public class DefaultArtifactVersion + implements ArtifactVersion +{ + private Integer majorVersion; + + private Integer minorVersion; + + private Integer incrementalVersion; + + private Integer buildNumber; + + private String qualifier; + + private ComparableVersion comparable; + + public DefaultArtifactVersion( String version ) + { + parseVersion( version ); + } + + @Override + public int hashCode() + { + return 11 + comparable.hashCode(); + } + + @Override + public boolean equals( Object other ) + { + if ( this == other ) + { + return true; + } + + if ( !( other instanceof ArtifactVersion ) ) + { + return false; + } + + return compareTo( (ArtifactVersion) other ) == 0; + } + + public int compareTo( ArtifactVersion otherVersion ) + { + if ( otherVersion instanceof DefaultArtifactVersion ) + { + return this.comparable.compareTo( ( (DefaultArtifactVersion) otherVersion ).comparable ); + } + else + { + return compareTo( new DefaultArtifactVersion( otherVersion.toString() ) ); + } + } + + public int getMajorVersion() + { + return majorVersion != null ? majorVersion : 0; + } + + public int getMinorVersion() + { + return minorVersion != null ? minorVersion : 0; + } + + public int getIncrementalVersion() + { + return incrementalVersion != null ? incrementalVersion : 0; + } + + public int getBuildNumber() + { + return buildNumber != null ? buildNumber : 0; + } + + public String getQualifier() + { + return qualifier; + } + + public final void parseVersion( String version ) + { + comparable = new ComparableVersion( version ); + + int index = version.indexOf( "-" ); + + String part1; + String part2 = null; + + if ( index < 0 ) + { + part1 = version; + } + else + { + part1 = version.substring( 0, index ); + part2 = version.substring( index + 1 ); + } + + if ( part2 != null ) + { + try + { + if ( ( part2.length() == 1 ) || !part2.startsWith( "0" ) ) + { + buildNumber = Integer.valueOf( part2 ); + } + else + { + qualifier = part2; + } + } + catch ( NumberFormatException e ) + { + qualifier = part2; + } + } + + if ( ( !part1.contains( "." ) ) && !part1.startsWith( "0" ) ) + { + try + { + majorVersion = Integer.valueOf( part1 ); + } + catch ( NumberFormatException e ) + { + // qualifier is the whole version, including "-" + qualifier = version; + buildNumber = null; + } + } + else + { + boolean fallback = false; + + StringTokenizer tok = new StringTokenizer( part1, "." ); + try + { + majorVersion = getNextIntegerToken( tok ); + if ( tok.hasMoreTokens() ) + { + minorVersion = getNextIntegerToken( tok ); + } + if ( tok.hasMoreTokens() ) + { + incrementalVersion = getNextIntegerToken( tok ); + } + if ( tok.hasMoreTokens() ) + { + qualifier = tok.nextToken(); + fallback = Pattern.compile( "\\d+" ).matcher( qualifier ).matches(); + } + + // string tokenzier won't detect these and ignores them + if ( part1.contains( ".." ) || part1.startsWith( "." ) || part1.endsWith( "." ) ) + { + fallback = true; + } + } + catch ( NumberFormatException e ) + { + fallback = true; + } + + if ( fallback ) + { + // qualifier is the whole version, including "-" + qualifier = version; + majorVersion = null; + minorVersion = null; + incrementalVersion = null; + buildNumber = null; + } + } + } + + private static Integer getNextIntegerToken( StringTokenizer tok ) + { + try + { + String s = tok.nextToken(); + if ( ( s.length() > 1 ) && s.startsWith( "0" ) ) + { + throw new NumberFormatException( "Number part has a leading 0: '" + s + "'" ); + } + return Integer.valueOf( s ); + } + catch ( NoSuchElementException e ) + { + throw new NumberFormatException( "Number is invalid" ); + } + } + + @Override + public String toString() + { + return comparable.toString(); + } +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/InvalidVersionSpecificationException.java b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/InvalidVersionSpecificationException.java new file mode 100644 index 00000000..adc48b93 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/InvalidVersionSpecificationException.java @@ -0,0 +1,34 @@ +package org.apache.maven.artifact.versioning; + +/* + * 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. + */ + +/** + * Occurs when a version is invalid. + * + * @author <a href="mailto:brett@apache.org">Brett Porter</a> + */ +public class InvalidVersionSpecificationException + extends Exception +{ + public InvalidVersionSpecificationException( String message ) + { + super( message ); + } +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/OverConstrainedVersionException.java b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/OverConstrainedVersionException.java new file mode 100644 index 00000000..bd8f3830 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/OverConstrainedVersionException.java @@ -0,0 +1,49 @@ +package org.apache.maven.artifact.versioning; + +/* + * 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. + */ + +import java.util.List; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.resolver.ArtifactResolutionException; + +/** + * Occurs when ranges exclude each other and no valid value remains. + * + * @author <a href="mailto:brett@apache.org">Brett Porter</a> + */ +public class OverConstrainedVersionException + extends ArtifactResolutionException +{ + public OverConstrainedVersionException( String msg, + Artifact artifact ) + { + super( msg, artifact ); + } + + public OverConstrainedVersionException( String msg, + Artifact artifact, + List<ArtifactRepository> remoteRepositories ) + { + super( msg, artifact, remoteRepositories ); + } + +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/Restriction.java b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/Restriction.java new file mode 100644 index 00000000..d73d7ea5 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/Restriction.java @@ -0,0 +1,195 @@ +package org.apache.maven.artifact.versioning; + +/* + * 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. + */ + +/** + * Describes a restriction in versioning. + * + * @author <a href="mailto:brett@apache.org">Brett Porter</a> + */ +public class Restriction +{ + private final ArtifactVersion lowerBound; + + private final boolean lowerBoundInclusive; + + private final ArtifactVersion upperBound; + + private final boolean upperBoundInclusive; + + public static final Restriction EVERYTHING = new Restriction( null, false, null, false ); + + public Restriction( ArtifactVersion lowerBound, boolean lowerBoundInclusive, ArtifactVersion upperBound, + boolean upperBoundInclusive ) + { + this.lowerBound = lowerBound; + this.lowerBoundInclusive = lowerBoundInclusive; + this.upperBound = upperBound; + this.upperBoundInclusive = upperBoundInclusive; + } + + public ArtifactVersion getLowerBound() + { + return lowerBound; + } + + public boolean isLowerBoundInclusive() + { + return lowerBoundInclusive; + } + + public ArtifactVersion getUpperBound() + { + return upperBound; + } + + public boolean isUpperBoundInclusive() + { + return upperBoundInclusive; + } + + public boolean containsVersion( ArtifactVersion version ) + { + if ( lowerBound != null ) + { + int comparison = lowerBound.compareTo( version ); + + if ( ( comparison == 0 ) && !lowerBoundInclusive ) + { + return false; + } + if ( comparison > 0 ) + { + return false; + } + } + if ( upperBound != null ) + { + int comparison = upperBound.compareTo( version ); + + if ( ( comparison == 0 ) && !upperBoundInclusive ) + { + return false; + } + if ( comparison < 0 ) + { + return false; + } + } + + return true; + } + + @Override + public int hashCode() + { + int result = 13; + + if ( lowerBound == null ) + { + result += 1; + } + else + { + result += lowerBound.hashCode(); + } + + result *= lowerBoundInclusive ? 1 : 2; + + if ( upperBound == null ) + { + result -= 3; + } + else + { + result -= upperBound.hashCode(); + } + + result *= upperBoundInclusive ? 2 : 3; + + return result; + } + + @Override + public boolean equals( Object other ) + { + if ( this == other ) + { + return true; + } + + if ( !( other instanceof Restriction ) ) + { + return false; + } + + Restriction restriction = (Restriction) other; + if ( lowerBound != null ) + { + if ( !lowerBound.equals( restriction.lowerBound ) ) + { + return false; + } + } + else if ( restriction.lowerBound != null ) + { + return false; + } + + if ( lowerBoundInclusive != restriction.lowerBoundInclusive ) + { + return false; + } + + if ( upperBound != null ) + { + if ( !upperBound.equals( restriction.upperBound ) ) + { + return false; + } + } + else if ( restriction.upperBound != null ) + { + return false; + } + + return upperBoundInclusive == restriction.upperBoundInclusive; + + } + + public String toString() + { + StringBuilder buf = new StringBuilder(); + + buf.append( isLowerBoundInclusive() ? "[" : "(" ); + if ( getLowerBound() != null ) + { + buf.append( getLowerBound().toString() ); + } + buf.append( "," ); + if ( getUpperBound() != null ) + { + buf.append( getUpperBound().toString() ); + } + buf.append( isUpperBoundInclusive() ? "]" : ")" ); + + return buf.toString(); + } +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/VersionRange.java b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/VersionRange.java new file mode 100644 index 00000000..dd8e028c --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/VersionRange.java @@ -0,0 +1,583 @@ +package org.apache.maven.artifact.versioning; + +/* + * 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. + */ + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; + +import org.apache.maven.artifact.Artifact; + +/** + * Construct a version range from a specification. + * + * @author <a href="mailto:brett@apache.org">Brett Porter</a> + */ +public class VersionRange +{ + private final ArtifactVersion recommendedVersion; + + private final List<Restriction> restrictions; + + private VersionRange( ArtifactVersion recommendedVersion, + List<Restriction> restrictions ) + { + this.recommendedVersion = recommendedVersion; + this.restrictions = restrictions; + } + + public ArtifactVersion getRecommendedVersion() + { + return recommendedVersion; + } + + public List<Restriction> getRestrictions() + { + return restrictions; + } + + public VersionRange cloneOf() + { + List<Restriction> copiedRestrictions = null; + + if ( restrictions != null ) + { + copiedRestrictions = new ArrayList<Restriction>(); + + if ( !restrictions.isEmpty() ) + { + copiedRestrictions.addAll( restrictions ); + } + } + + return new VersionRange( recommendedVersion, copiedRestrictions ); + } + + /** + * Create a version range from a string representation + * <p/> + * Some spec examples are + * <ul> + * <li><code>1.0</code> Version 1.0</li> + * <li><code>[1.0,2.0)</code> Versions 1.0 (included) to 2.0 (not included)</li> + * <li><code>[1.0,2.0]</code> Versions 1.0 to 2.0 (both included)</li> + * <li><code>[1.5,)</code> Versions 1.5 and higher</li> + * <li><code>(,1.0],[1.2,)</code> Versions up to 1.0 (included) and 1.2 or higher</li> + * </ul> + * + * @param spec string representation of a version or version range + * @return a new {@link VersionRange} object that represents the spec + * @throws InvalidVersionSpecificationException + * + */ + public static VersionRange createFromVersionSpec( String spec ) + throws InvalidVersionSpecificationException + { + if ( spec == null ) + { + return null; + } + + List<Restriction> restrictions = new ArrayList<Restriction>(); + String process = spec; + ArtifactVersion version = null; + ArtifactVersion upperBound = null; + ArtifactVersion lowerBound = null; + + while ( process.startsWith( "[" ) || process.startsWith( "(" ) ) + { + int index1 = process.indexOf( ")" ); + int index2 = process.indexOf( "]" ); + + int index = index2; + if ( index2 < 0 || index1 < index2 ) + { + if ( index1 >= 0 ) + { + index = index1; + } + } + + if ( index < 0 ) + { + throw new InvalidVersionSpecificationException( "Unbounded range: " + spec ); + } + + Restriction restriction = parseRestriction( process.substring( 0, index + 1 ) ); + if ( lowerBound == null ) + { + lowerBound = restriction.getLowerBound(); + } + if ( upperBound != null ) + { + if ( restriction.getLowerBound() == null || restriction.getLowerBound().compareTo( upperBound ) < 0 ) + { + throw new InvalidVersionSpecificationException( "Ranges overlap: " + spec ); + } + } + restrictions.add( restriction ); + upperBound = restriction.getUpperBound(); + + process = process.substring( index + 1 ).trim(); + + if ( process.length() > 0 && process.startsWith( "," ) ) + { + process = process.substring( 1 ).trim(); + } + } + + if ( process.length() > 0 ) + { + if ( restrictions.size() > 0 ) + { + throw new InvalidVersionSpecificationException( + "Only fully-qualified sets allowed in multiple set scenario: " + spec ); + } + else + { + version = new DefaultArtifactVersion( process ); + restrictions.add( Restriction.EVERYTHING ); + } + } + + return new VersionRange( version, restrictions ); + } + + private static Restriction parseRestriction( String spec ) + throws InvalidVersionSpecificationException + { + boolean lowerBoundInclusive = spec.startsWith( "[" ); + boolean upperBoundInclusive = spec.endsWith( "]" ); + + String process = spec.substring( 1, spec.length() - 1 ).trim(); + + Restriction restriction; + + int index = process.indexOf( "," ); + + if ( index < 0 ) + { + if ( !lowerBoundInclusive || !upperBoundInclusive ) + { + throw new InvalidVersionSpecificationException( "Single version must be surrounded by []: " + spec ); + } + + ArtifactVersion version = new DefaultArtifactVersion( process ); + + restriction = new Restriction( version, lowerBoundInclusive, version, upperBoundInclusive ); + } + else + { + String lowerBound = process.substring( 0, index ).trim(); + String upperBound = process.substring( index + 1 ).trim(); + if ( lowerBound.equals( upperBound ) ) + { + throw new InvalidVersionSpecificationException( "Range cannot have identical boundaries: " + spec ); + } + + ArtifactVersion lowerVersion = null; + if ( lowerBound.length() > 0 ) + { + lowerVersion = new DefaultArtifactVersion( lowerBound ); + } + ArtifactVersion upperVersion = null; + if ( upperBound.length() > 0 ) + { + upperVersion = new DefaultArtifactVersion( upperBound ); + } + + if ( upperVersion != null && lowerVersion != null && upperVersion.compareTo( lowerVersion ) < 0 ) + { + throw new InvalidVersionSpecificationException( "Range defies version ordering: " + spec ); + } + + restriction = new Restriction( lowerVersion, lowerBoundInclusive, upperVersion, upperBoundInclusive ); + } + + return restriction; + } + + public static VersionRange createFromVersion( String version ) + { + List<Restriction> restrictions = Collections.emptyList(); + return new VersionRange( new DefaultArtifactVersion( version ), restrictions ); + } + + /** + * Creates and returns a new <code>VersionRange</code> that is a restriction of this + * version range and the specified version range. + * <p> + * Note: Precedence is given to the recommended version from this version range over the + * recommended version from the specified version range. + * </p> + * + * @param restriction the <code>VersionRange</code> that will be used to restrict this version + * range. + * @return the <code>VersionRange</code> that is a restriction of this version range and the + * specified version range. + * <p> + * The restrictions of the returned version range will be an intersection of the restrictions + * of this version range and the specified version range if both version ranges have + * restrictions. Otherwise, the restrictions on the returned range will be empty. + * </p> + * <p> + * The recommended version of the returned version range will be the recommended version of + * this version range, provided that ranges falls within the intersected restrictions. If + * the restrictions are empty, this version range's recommended version is used if it is not + * <code>null</code>. If it is <code>null</code>, the specified version range's recommended + * version is used (provided it is non-<code>null</code>). If no recommended version can be + * obtained, the returned version range's recommended version is set to <code>null</code>. + * </p> + * @throws NullPointerException if the specified <code>VersionRange</code> is + * <code>null</code>. + */ + public VersionRange restrict( VersionRange restriction ) + { + List<Restriction> r1 = this.restrictions; + List<Restriction> r2 = restriction.restrictions; + List<Restriction> restrictions; + + if ( r1.isEmpty() || r2.isEmpty() ) + { + restrictions = Collections.emptyList(); + } + else + { + restrictions = intersection( r1, r2 ); + } + + ArtifactVersion version = null; + if ( restrictions.size() > 0 ) + { + for ( Restriction r : restrictions ) + { + if ( recommendedVersion != null && r.containsVersion( recommendedVersion ) ) + { + // if we find the original, use that + version = recommendedVersion; + break; + } + else if ( version == null && restriction.getRecommendedVersion() != null + && r.containsVersion( restriction.getRecommendedVersion() ) ) + { + // use this if we can, but prefer the original if possible + version = restriction.getRecommendedVersion(); + } + } + } + // Either the original or the specified version ranges have no restrictions + else if ( recommendedVersion != null ) + { + // Use the original recommended version since it exists + version = recommendedVersion; + } + else if ( restriction.recommendedVersion != null ) + { + // Use the recommended version from the specified VersionRange since there is no + // original recommended version + version = restriction.recommendedVersion; + } +/* TODO: should throw this immediately, but need artifact + else + { + throw new OverConstrainedVersionException( "Restricting incompatible version ranges" ); + } +*/ + + return new VersionRange( version, restrictions ); + } + + private List<Restriction> intersection( List<Restriction> r1, List<Restriction> r2 ) + { + List<Restriction> restrictions = new ArrayList<Restriction>( r1.size() + r2.size() ); + Iterator<Restriction> i1 = r1.iterator(); + Iterator<Restriction> i2 = r2.iterator(); + Restriction res1 = i1.next(); + Restriction res2 = i2.next(); + + boolean done = false; + while ( !done ) + { + if ( res1.getLowerBound() == null || res2.getUpperBound() == null + || res1.getLowerBound().compareTo( res2.getUpperBound() ) <= 0 ) + { + if ( res1.getUpperBound() == null || res2.getLowerBound() == null + || res1.getUpperBound().compareTo( res2.getLowerBound() ) >= 0 ) + { + ArtifactVersion lower; + ArtifactVersion upper; + boolean lowerInclusive; + boolean upperInclusive; + + // overlaps + if ( res1.getLowerBound() == null ) + { + lower = res2.getLowerBound(); + lowerInclusive = res2.isLowerBoundInclusive(); + } + else if ( res2.getLowerBound() == null ) + { + lower = res1.getLowerBound(); + lowerInclusive = res1.isLowerBoundInclusive(); + } + else + { + int comparison = res1.getLowerBound().compareTo( res2.getLowerBound() ); + if ( comparison < 0 ) + { + lower = res2.getLowerBound(); + lowerInclusive = res2.isLowerBoundInclusive(); + } + else if ( comparison == 0 ) + { + lower = res1.getLowerBound(); + lowerInclusive = res1.isLowerBoundInclusive() && res2.isLowerBoundInclusive(); + } + else + { + lower = res1.getLowerBound(); + lowerInclusive = res1.isLowerBoundInclusive(); + } + } + + if ( res1.getUpperBound() == null ) + { + upper = res2.getUpperBound(); + upperInclusive = res2.isUpperBoundInclusive(); + } + else if ( res2.getUpperBound() == null ) + { + upper = res1.getUpperBound(); + upperInclusive = res1.isUpperBoundInclusive(); + } + else + { + int comparison = res1.getUpperBound().compareTo( res2.getUpperBound() ); + if ( comparison < 0 ) + { + upper = res1.getUpperBound(); + upperInclusive = res1.isUpperBoundInclusive(); + } + else if ( comparison == 0 ) + { + upper = res1.getUpperBound(); + upperInclusive = res1.isUpperBoundInclusive() && res2.isUpperBoundInclusive(); + } + else + { + upper = res2.getUpperBound(); + upperInclusive = res2.isUpperBoundInclusive(); + } + } + + // don't add if they are equal and one is not inclusive + if ( lower == null || upper == null || lower.compareTo( upper ) != 0 ) + { + restrictions.add( new Restriction( lower, lowerInclusive, upper, upperInclusive ) ); + } + else if ( lowerInclusive && upperInclusive ) + { + restrictions.add( new Restriction( lower, lowerInclusive, upper, upperInclusive ) ); + } + + //noinspection ObjectEquality + if ( upper == res2.getUpperBound() ) + { + // advance res2 + if ( i2.hasNext() ) + { + res2 = i2.next(); + } + else + { + done = true; + } + } + else + { + // advance res1 + if ( i1.hasNext() ) + { + res1 = i1.next(); + } + else + { + done = true; + } + } + } + else + { + // move on to next in r1 + if ( i1.hasNext() ) + { + res1 = i1.next(); + } + else + { + done = true; + } + } + } + else + { + // move on to next in r2 + if ( i2.hasNext() ) + { + res2 = i2.next(); + } + else + { + done = true; + } + } + } + + return restrictions; + } + + public ArtifactVersion getSelectedVersion( Artifact artifact ) + throws OverConstrainedVersionException + { + ArtifactVersion version; + if ( recommendedVersion != null ) + { + version = recommendedVersion; + } + else + { + if ( restrictions.size() == 0 ) + { + throw new OverConstrainedVersionException( "The artifact has no valid ranges", artifact ); + } + + version = null; + } + return version; + } + + public boolean isSelectedVersionKnown( Artifact artifact ) + throws OverConstrainedVersionException + { + boolean value = false; + if ( recommendedVersion != null ) + { + value = true; + } + else + { + if ( restrictions.size() == 0 ) + { + throw new OverConstrainedVersionException( "The artifact has no valid ranges", artifact ); + } + } + return value; + } + + public String toString() + { + if ( recommendedVersion != null ) + { + return recommendedVersion.toString(); + } + else + { + StringBuilder buf = new StringBuilder(); + for ( Iterator<Restriction> i = restrictions.iterator(); i.hasNext(); ) + { + Restriction r = i.next(); + + buf.append( r.toString() ); + + if ( i.hasNext() ) + { + buf.append( ',' ); + } + } + return buf.toString(); + } + } + + public ArtifactVersion matchVersion( List<ArtifactVersion> versions ) + { + // TODO: could be more efficient by sorting the list and then moving along the restrictions in order? + + ArtifactVersion matched = null; + for ( ArtifactVersion version : versions ) + { + if ( containsVersion( version ) ) + { + // valid - check if it is greater than the currently matched version + if ( matched == null || version.compareTo( matched ) > 0 ) + { + matched = version; + } + } + } + return matched; + } + + public boolean containsVersion( ArtifactVersion version ) + { + for ( Restriction restriction : restrictions ) + { + if ( restriction.containsVersion( version ) ) + { + return true; + } + } + return false; + } + + public boolean hasRestrictions() + { + return !restrictions.isEmpty() && recommendedVersion == null; + } + + public boolean equals( Object obj ) + { + if ( this == obj ) + { + return true; + } + if ( !( obj instanceof VersionRange ) ) + { + return false; + } + VersionRange other = (VersionRange) obj; + + boolean equals = + recommendedVersion == other.recommendedVersion + || ( ( recommendedVersion != null ) && recommendedVersion.equals( other.recommendedVersion ) ); + equals &= + restrictions == other.restrictions + || ( ( restrictions != null ) && restrictions.equals( other.restrictions ) ); + return equals; + } + + public int hashCode() + { + int hash = 7; + hash = 31 * hash + ( recommendedVersion == null ? 0 : recommendedVersion.hashCode() ); + hash = 31 * hash + ( restrictions == null ? 0 : restrictions.hashCode() ); + return hash; + } +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/repository/Proxy.java b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/repository/Proxy.java new file mode 100644 index 00000000..ea2c0238 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/repository/Proxy.java @@ -0,0 +1,197 @@ +package org.apache.maven.repository; + +/* + * 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. + */ + +public class Proxy +{ + public static final String PROXY_SOCKS5 = "SOCKS_5"; + + public static final String PROXY_SOCKS4 = "SOCKS4"; + + public static final String PROXY_HTTP = "HTTP"; + + /** + * Proxy server host + */ + private String host; + + /** + * Username used to access the proxy server + */ + private String userName; + + /** + * Password associated with the proxy server + */ + private String password; + + /** + * Proxy server port + */ + private int port; + + /** + * Type of the proxy + */ + private String protocol; + + /** + * The non-proxy hosts. Follows Java system property format: <code>*.foo.com|localhost</code>. + */ + private String nonProxyHosts; + + /** + * For NTLM proxies, specifies the NTLM host. + */ + private String ntlmHost; + + /** + * For NTLM proxies, specifies the NTLM domain. + */ + private String ntlmDomain; + + /** + * Return proxy server host name. + * + * @return proxy server host name + */ + public String getHost() + { + return host; + } + + /** + * Set proxy host name. + * + * @param host proxy server host name + */ + public void setHost( String host ) + { + this.host = host; + } + + /** + * Get user's password used to login to proxy server. + * + * @return user's password at proxy host + */ + public String getPassword() + { + return password; + } + + /** + * Set the user's password for the proxy server. + * + * @param password password to use to login to a proxy server + */ + public void setPassword( String password ) + { + this.password = password; + } + + /** + * Get the proxy port. + * + * @return proxy server port + */ + public int getPort() + { + return port; + } + + /** + * Set the proxy port. + * + * @param port proxy server port + */ + public void setPort( int port ) + { + this.port = port; + } + + /** + * Get the proxy username. + * + * @return username for the proxy server + */ + public String getUserName() + { + return userName; + } + + /** + * Set the proxy username. + * + * @param userName username for the proxy server + */ + public void setUserName( String userName ) + { + this.userName = userName; + } + + /** + * Get the type of the proxy server. + * + * @return the type of the proxy server + */ + public String getProtocol() + { + return protocol; + } + + /** + * @param type the type of the proxy server like <i>SOCKSv4</i> + */ + public void setProtocol( String protocol ) + { + this.protocol = protocol; + } + + public String getNonProxyHosts() + { + return nonProxyHosts; + } + + public void setNonProxyHosts( String nonProxyHosts ) + { + this.nonProxyHosts = nonProxyHosts; + } + + public String getNtlmHost() + { + return ntlmHost; + } + + public void setNtlmHost( String ntlmHost ) + { + this.ntlmHost = ntlmHost; + } + + public void setNtlmDomain( String ntlmDomain ) + { + this.ntlmDomain = ntlmDomain; + } + + public String getNtlmDomain() + { + return ntlmDomain; + } +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/repository/legacy/metadata/ArtifactMetadata.java b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/repository/legacy/metadata/ArtifactMetadata.java new file mode 100644 index 00000000..e66a84a9 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/main/java/org/apache/maven/repository/legacy/metadata/ArtifactMetadata.java @@ -0,0 +1,83 @@ +package org.apache.maven.repository.legacy.metadata; + +/* + * 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. + */ + +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.metadata.RepositoryMetadataStoreException; + +/** + * Contains metadata about an artifact, and methods to retrieve/store it from an artifact repository. + * + * @author <a href="mailto:brett@apache.org">Brett Porter</a> + * @todo merge with artifactmetadatasource + * @todo retrieval exception not appropriate for store + */ +public interface ArtifactMetadata +{ + /** Whether this metadata should be stored alongside the artifact. */ + boolean storedInArtifactVersionDirectory(); + + /** Whether this metadata should be stored alongside the group. */ + boolean storedInGroupDirectory(); + + String getGroupId(); + + String getArtifactId(); + + String getBaseVersion(); + + Object getKey(); + + /** + * Get the filename of this metadata on the local repository. + * + * @param repository the remote repository it came from + * @return the filename + */ + String getLocalFilename( ArtifactRepository repository ); + + /** + * Get the filename of this metadata on the remote repository. + * + * @return the filename + */ + String getRemoteFilename(); + + /** + * Merge a new metadata set into this piece of metadata. + * + * @param metadata the new metadata + * @todo this should only be needed on the repository metadata + */ + void merge( ArtifactMetadata metadata ); + + /** + * Store the metadata in the local repository. + * + * @param localRepository the local repository + * @param remoteRepository the remote repository it came from + * @todo this should only be needed on the repository metadata + */ + void storeInLocalRepository( ArtifactRepository localRepository, + ArtifactRepository remoteRepository ) + throws RepositoryMetadataStoreException; + + String extendedToString(); +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/site/apt/index.apt b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/site/apt/index.apt new file mode 100644 index 00000000..f796c118 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/site/apt/index.apt @@ -0,0 +1,47 @@ +~~ 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. + + ----- + Introduction + ----- + Hervé Boutemy + ----- + 2014-11-30 + ----- + +Maven Artifact + + Maven Artifact classes, providing <<<Artifact>>> interface ({{{./apidocs/org/apache/maven/artifact/Artifact.html}javadoc}}), + with its <<<DefaultArtifact>>> implementation ({{{./xref/org/apache/maven/artifact/DefaultArtifact.html}source}}). + + The jar file is executable and provides a little tool to display how Maven parses and compares versions: + ++----+ +$ java -jar maven-artifact-*.jar 3.2.4-alpha-1 3.2.4-SNAPSHOT 3.2.4.0 +Display parameters as parsed by Maven (in canonical form) and comparison result: +1. 3.2.4-alpha-1 == 3.2.4.alpha.1 + 3.2.4-alpha-1 < 3.2.4-SNAPSHOT +2. 3.2.4-SNAPSHOT == 3.2.4.snapshot + 3.2.4-SNAPSHOT < 3.2.4.0 +3. 3.2.4.0 == 3.2.4 ++----+ + +* Useful entry points + + * artifact version comparison {{{./apidocs/org/apache/maven/artifact/versioning/ComparableVersion.html}javadoc}}, + + * {{{./apidocs/org/apache/maven/artifact/versioning/VersionRange.html}version range}}. diff --git a/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/site/site.xml b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/site/site.xml new file mode 100644 index 00000000..3a16bf98 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/site/site.xml @@ -0,0 +1,36 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- +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. +--> + +<project xmlns="http://maven.apache.org/DECORATION/1.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/DECORATION/1.0.0 http://maven.apache.org/xsd/decoration-1.0.0.xsd"> + <body> + <menu name="Overview"> + <item name="Introduction" href="index.html"/> + <item name="JavaDocs" href="apidocs/index.html"/> + <item name="Source Xref" href="xref/index.html"/> + <!--item name="FAQ" href="faq.html"/--> + </menu> + + <menu ref="parent"/> + <menu ref="reports"/> + </body> +</project>
\ No newline at end of file diff --git a/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/ComparableVersionTest.java b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/ComparableVersionTest.java new file mode 100644 index 00000000..6cf372f7 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/ComparableVersionTest.java @@ -0,0 +1,231 @@ +package org.apache.maven.artifact.versioning; + +/* + * 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. + */ + +import java.util.Locale; + +import junit.framework.TestCase; + +/** + * Test ComparableVersion. + * + * @author <a href="mailto:hboutemy@apache.org">Hervé Boutemy</a> + */ +@SuppressWarnings( "unchecked" ) +public class ComparableVersionTest + extends TestCase +{ + private Comparable newComparable( String version ) + { + ComparableVersion ret = new ComparableVersion( version ); + String canonical = ret.getCanonical(); + String parsedCanonical = new ComparableVersion( canonical ).getCanonical(); + + System.out.println( "canonical( " + version + " ) = " + canonical ); + assertEquals( "canonical( " + version + " ) = " + canonical + " -> canonical: " + parsedCanonical, canonical, + parsedCanonical ); + + return ret; + } + + private static final String[] VERSIONS_QUALIFIER = + { "1-alpha2snapshot", "1-alpha2", "1-alpha-123", "1-beta-2", "1-beta123", "1-m2", "1-m11", "1-rc", "1-cr2", + "1-rc123", "1-SNAPSHOT", "1", "1-sp", "1-sp2", "1-sp123", "1-abc", "1-def", "1-pom-1", "1-1-snapshot", + "1-1", "1-2", "1-123" }; + + private static final String[] VERSIONS_NUMBER = + { "2.0", "2-1", "2.0.a", "2.0.0.a", "2.0.2", "2.0.123", "2.1.0", "2.1-a", "2.1b", "2.1-c", "2.1-1", "2.1.0.1", + "2.2", "2.123", "11.a2", "11.a11", "11.b2", "11.b11", "11.m2", "11.m11", "11", "11.a", "11b", "11c", "11m" }; + + private void checkVersionsOrder( String[] versions ) + { + Comparable[] c = new Comparable[versions.length]; + for ( int i = 0; i < versions.length; i++ ) + { + c[i] = newComparable( versions[i] ); + } + + for ( int i = 1; i < versions.length; i++ ) + { + Comparable low = c[i - 1]; + for ( int j = i; j < versions.length; j++ ) + { + Comparable high = c[j]; + assertTrue( "expected " + low + " < " + high, low.compareTo( high ) < 0 ); + assertTrue( "expected " + high + " > " + low, high.compareTo( low ) > 0 ); + } + } + } + + private void checkVersionsEqual( String v1, String v2 ) + { + Comparable c1 = newComparable( v1 ); + Comparable c2 = newComparable( v2 ); + assertTrue( "expected " + v1 + " == " + v2, c1.compareTo( c2 ) == 0 ); + assertTrue( "expected " + v2 + " == " + v1, c2.compareTo( c1 ) == 0 ); + assertTrue( "expected same hashcode for " + v1 + " and " + v2, c1.hashCode() == c2.hashCode() ); + assertTrue( "expected " + v1 + ".equals( " + v2 + " )", c1.equals( c2 ) ); + assertTrue( "expected " + v2 + ".equals( " + v1 + " )", c2.equals( c1 ) ); + } + + private void checkVersionsOrder( String v1, String v2 ) + { + Comparable c1 = newComparable( v1 ); + Comparable c2 = newComparable( v2 ); + assertTrue( "expected " + v1 + " < " + v2, c1.compareTo( c2 ) < 0 ); + assertTrue( "expected " + v2 + " > " + v1, c2.compareTo( c1 ) > 0 ); + } + + public void testVersionsQualifier() + { + checkVersionsOrder( VERSIONS_QUALIFIER ); + } + + public void testVersionsNumber() + { + checkVersionsOrder( VERSIONS_NUMBER ); + } + + public void testVersionsEqual() + { + newComparable( "1.0-alpha" ); + checkVersionsEqual( "1", "1" ); + checkVersionsEqual( "1", "1.0" ); + checkVersionsEqual( "1", "1.0.0" ); + checkVersionsEqual( "1.0", "1.0.0" ); + checkVersionsEqual( "1", "1-0" ); + checkVersionsEqual( "1", "1.0-0" ); + checkVersionsEqual( "1.0", "1.0-0" ); + // no separator between number and character + checkVersionsEqual( "1a", "1-a" ); + checkVersionsEqual( "1a", "1.0-a" ); + checkVersionsEqual( "1a", "1.0.0-a" ); + checkVersionsEqual( "1.0a", "1-a" ); + checkVersionsEqual( "1.0.0a", "1-a" ); + checkVersionsEqual( "1x", "1-x" ); + checkVersionsEqual( "1x", "1.0-x" ); + checkVersionsEqual( "1x", "1.0.0-x" ); + checkVersionsEqual( "1.0x", "1-x" ); + checkVersionsEqual( "1.0.0x", "1-x" ); + + // aliases + checkVersionsEqual( "1ga", "1" ); + checkVersionsEqual( "1final", "1" ); + checkVersionsEqual( "1cr", "1rc" ); + + // special "aliases" a, b and m for alpha, beta and milestone + checkVersionsEqual( "1a1", "1-alpha-1" ); + checkVersionsEqual( "1b2", "1-beta-2" ); + checkVersionsEqual( "1m3", "1-milestone-3" ); + + // case insensitive + checkVersionsEqual( "1X", "1x" ); + checkVersionsEqual( "1A", "1a" ); + checkVersionsEqual( "1B", "1b" ); + checkVersionsEqual( "1M", "1m" ); + checkVersionsEqual( "1Ga", "1" ); + checkVersionsEqual( "1GA", "1" ); + checkVersionsEqual( "1Final", "1" ); + checkVersionsEqual( "1FinaL", "1" ); + checkVersionsEqual( "1FINAL", "1" ); + checkVersionsEqual( "1Cr", "1Rc" ); + checkVersionsEqual( "1cR", "1rC" ); + checkVersionsEqual( "1m3", "1Milestone3" ); + checkVersionsEqual( "1m3", "1MileStone3" ); + checkVersionsEqual( "1m3", "1MILESTONE3" ); + } + + public void testVersionComparing() + { + checkVersionsOrder( "1", "2" ); + checkVersionsOrder( "1.5", "2" ); + checkVersionsOrder( "1", "2.5" ); + checkVersionsOrder( "1.0", "1.1" ); + checkVersionsOrder( "1.1", "1.2" ); + checkVersionsOrder( "1.0.0", "1.1" ); + checkVersionsOrder( "1.0.1", "1.1" ); + checkVersionsOrder( "1.1", "1.2.0" ); + + checkVersionsOrder( "1.0-alpha-1", "1.0" ); + checkVersionsOrder( "1.0-alpha-1", "1.0-alpha-2" ); + checkVersionsOrder( "1.0-alpha-1", "1.0-beta-1" ); + + checkVersionsOrder( "1.0-beta-1", "1.0-SNAPSHOT" ); + checkVersionsOrder( "1.0-SNAPSHOT", "1.0" ); + checkVersionsOrder( "1.0-alpha-1-SNAPSHOT", "1.0-alpha-1" ); + + checkVersionsOrder( "1.0", "1.0-1" ); + checkVersionsOrder( "1.0-1", "1.0-2" ); + checkVersionsOrder( "1.0.0", "1.0-1" ); + + checkVersionsOrder( "2.0-1", "2.0.1" ); + checkVersionsOrder( "2.0.1-klm", "2.0.1-lmn" ); + checkVersionsOrder( "2.0.1", "2.0.1-xyz" ); + + checkVersionsOrder( "2.0.1", "2.0.1-123" ); + checkVersionsOrder( "2.0.1-xyz", "2.0.1-123" ); + } + + /** + * Test <a href="https://jira.codehaus.org/browse/MNG-5568">MNG-5568</a> edge case + * which was showing transitive inconsistency: since A > B and B > C then we should have A > C + * otherwise sorting a list of ComparableVersions() will in some cases throw runtime exception; + * see Netbeans issues <a href="https://netbeans.org/bugzilla/show_bug.cgi?id=240845">240845</a> and + * <a href="https://netbeans.org/bugzilla/show_bug.cgi?id=226100">226100</a> + */ + public void testMng5568() + { + String a = "6.1.0"; + String b = "6.1.0rc3"; + String c = "6.1H.5-beta"; // this is the unusual version string, with 'H' in the middle + + checkVersionsOrder( b, a ); // classical + checkVersionsOrder( b, c ); // now b < c, but before MNG-5568, we had b > c + checkVersionsOrder( a, c ); + } + + public void testLocaleIndependent() + { + Locale orig = Locale.getDefault(); + Locale[] locales = { Locale.ENGLISH, new Locale( "tr" ), Locale.getDefault() }; + try + { + for ( Locale locale : locales ) + { + Locale.setDefault( locale ); + checkVersionsEqual( "1-abcdefghijklmnopqrstuvwxyz", "1-ABCDEFGHIJKLMNOPQRSTUVWXYZ" ); + } + } + finally + { + Locale.setDefault( orig ); + } + } + + public void testReuse() + { + ComparableVersion c1 = new ComparableVersion( "1" ); + c1.parseVersion( "2" ); + + Comparable c2 = newComparable( "2" ); + + assertEquals( "reused instance should be equivalent to new instance", c1, c2 ); + } +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/DefaultArtifactVersionTest.java b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/DefaultArtifactVersionTest.java new file mode 100644 index 00000000..fc5a2742 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/DefaultArtifactVersionTest.java @@ -0,0 +1,223 @@ +package org.apache.maven.artifact.versioning; + +/* + * 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. + */ + +import junit.framework.TestCase; + +/** + * Test DefaultArtifactVersion. + * + * @author <a href="mailto:brett@apache.org">Brett Porter</a> + */ +public class DefaultArtifactVersionTest + extends TestCase +{ + private ArtifactVersion newArtifactVersion( String version ) + { + return new DefaultArtifactVersion( version ); + } + + private void checkVersionParsing( String version, int major, int minor, int incremental, int buildnumber, + String qualifier ) + { + ArtifactVersion artifactVersion = newArtifactVersion( version ); + String parsed = + "'" + version + "' parsed as ('" + artifactVersion.getMajorVersion() + "', '" + + artifactVersion.getMinorVersion() + "', '" + artifactVersion.getIncrementalVersion() + "', '" + + artifactVersion.getBuildNumber() + "', '" + artifactVersion.getQualifier() + "'), "; + assertEquals( parsed + "check major version", major, artifactVersion.getMajorVersion() ); + assertEquals( parsed + "check minor version", minor, artifactVersion.getMinorVersion() ); + assertEquals( parsed + "check incremental version", incremental, artifactVersion.getIncrementalVersion() ); + assertEquals( parsed + "check build number", buildnumber, artifactVersion.getBuildNumber() ); + assertEquals( parsed + "check qualifier", qualifier, artifactVersion.getQualifier() ); + assertEquals( "check " + version + " string value", version, artifactVersion.toString() ); + } + + public void testVersionParsing() + { + checkVersionParsing( "1", 1, 0, 0, 0, null ); + checkVersionParsing( "1.2", 1, 2, 0, 0, null ); + checkVersionParsing( "1.2.3", 1, 2, 3, 0, null ); + checkVersionParsing( "1.2.3-1", 1, 2, 3, 1, null ); + checkVersionParsing( "1.2.3-alpha-1", 1, 2, 3, 0, "alpha-1" ); + checkVersionParsing( "1.2-alpha-1", 1, 2, 0, 0, "alpha-1" ); + checkVersionParsing( "1.2-alpha-1-20050205.060708-1", 1, 2, 0, 0, "alpha-1-20050205.060708-1" ); + checkVersionParsing( "RELEASE", 0, 0, 0, 0, "RELEASE" ); + checkVersionParsing( "2.0-1", 2, 0, 0, 1, null ); + + // 0 at the beginning of a number has a special handling + checkVersionParsing( "02", 0, 0, 0, 0, "02" ); + checkVersionParsing( "0.09", 0, 0, 0, 0, "0.09" ); + checkVersionParsing( "0.2.09", 0, 0, 0, 0, "0.2.09" ); + checkVersionParsing( "2.0-01", 2, 0, 0, 0, "01" ); + + // version schemes not really supported: fully transformed as qualifier + checkVersionParsing( "1.0.1b", 0, 0, 0, 0, "1.0.1b" ); + checkVersionParsing( "1.0M2", 0, 0, 0, 0, "1.0M2" ); + checkVersionParsing( "1.0RC2", 0, 0, 0, 0, "1.0RC2" ); + checkVersionParsing( "1.1.2.beta1", 1, 1, 2, 0, "beta1" ); + checkVersionParsing( "1.7.3.beta1", 1, 7, 3, 0, "beta1" ); + checkVersionParsing( "1.7.3.0", 0, 0, 0, 0, "1.7.3.0" ); + checkVersionParsing( "1.7.3.0-1", 0, 0, 0, 0, "1.7.3.0-1" ); + checkVersionParsing( "PATCH-1193602", 0, 0, 0, 0, "PATCH-1193602" ); + checkVersionParsing( "5.0.0alpha-2006020117", 0, 0, 0, 0, "5.0.0alpha-2006020117" ); + checkVersionParsing( "1.0.0.-SNAPSHOT", 0, 0, 0, 0, "1.0.0.-SNAPSHOT" ); + checkVersionParsing( "1..0-SNAPSHOT", 0, 0, 0, 0, "1..0-SNAPSHOT" ); + checkVersionParsing( "1.0.-SNAPSHOT", 0, 0, 0, 0, "1.0.-SNAPSHOT" ); + checkVersionParsing( ".1.0-SNAPSHOT", 0, 0, 0, 0, ".1.0-SNAPSHOT" ); + + checkVersionParsing( "1.2.3.200705301630", 0, 0, 0, 0, "1.2.3.200705301630" ); + checkVersionParsing( "1.2.3-200705301630", 1, 2, 3, 0, "200705301630" ); + } + + public void testVersionComparing() + { + assertVersionEqual( "1", "1" ); + assertVersionOlder( "1", "2" ); + assertVersionOlder( "1.5", "2" ); + assertVersionOlder( "1", "2.5" ); + assertVersionEqual( "1", "1.0" ); + assertVersionEqual( "1", "1.0.0" ); + assertVersionOlder( "1.0", "1.1" ); + assertVersionOlder( "1.1", "1.2" ); + assertVersionOlder( "1.0.0", "1.1" ); + assertVersionOlder( "1.1", "1.2.0" ); + + assertVersionOlder( "1.1.2.alpha1", "1.1.2" ); + assertVersionOlder( "1.1.2.alpha1", "1.1.2.beta1" ); + assertVersionOlder( "1.1.2.beta1", "1.2" ); + + assertVersionOlder( "1.0-alpha-1", "1.0" ); + assertVersionOlder( "1.0-alpha-1", "1.0-alpha-2" ); + assertVersionOlder( "1.0-alpha-2", "1.0-alpha-15" ); + assertVersionOlder( "1.0-alpha-1", "1.0-beta-1" ); + + assertVersionOlder( "1.0-beta-1", "1.0-SNAPSHOT" ); + assertVersionOlder( "1.0-SNAPSHOT", "1.0" ); + assertVersionOlder( "1.0-alpha-1-SNAPSHOT", "1.0-alpha-1" ); + + assertVersionOlder( "1.0", "1.0-1" ); + assertVersionOlder( "1.0-1", "1.0-2" ); + assertVersionEqual( "2.0-0", "2.0" ); + assertVersionOlder( "2.0", "2.0-1" ); + assertVersionOlder( "2.0.0", "2.0-1" ); + assertVersionOlder( "2.0-1", "2.0.1" ); + + assertVersionOlder( "2.0.1-klm", "2.0.1-lmn" ); + assertVersionOlder( "2.0.1", "2.0.1-xyz" ); + assertVersionOlder( "2.0.1-xyz-1", "2.0.1-1-xyz" ); + + assertVersionOlder( "2.0.1", "2.0.1-123" ); + assertVersionOlder( "2.0.1-xyz", "2.0.1-123" ); + + assertVersionOlder( "1.2.3-10000000000", "1.2.3-10000000001" ); + assertVersionOlder( "1.2.3-1", "1.2.3-10000000001" ); + assertVersionOlder( "2.3.0-v200706262000", "2.3.0-v200706262130" ); // org.eclipse:emf:2.3.0-v200706262000 + // org.eclipse.wst.common_core.feature_2.0.0.v200706041905-7C78EK9E_EkMNfNOd2d8qq + assertVersionOlder( "2.0.0.v200706041905-7C78EK9E_EkMNfNOd2d8qq", "2.0.0.v200706041906-7C78EK9E_EkMNfNOd2d8qq" ); + } + + public void testVersionSnapshotComparing() + { + assertVersionEqual( "1-SNAPSHOT", "1-SNAPSHOT" ); + assertVersionOlder( "1-SNAPSHOT", "2-SNAPSHOT" ); + assertVersionOlder( "1.5-SNAPSHOT", "2-SNAPSHOT" ); + assertVersionOlder( "1-SNAPSHOT", "2.5-SNAPSHOT" ); + assertVersionEqual( "1-SNAPSHOT", "1.0-SNAPSHOT" ); + assertVersionEqual( "1-SNAPSHOT", "1.0.0-SNAPSHOT" ); + assertVersionOlder( "1.0-SNAPSHOT", "1.1-SNAPSHOT" ); + assertVersionOlder( "1.1-SNAPSHOT", "1.2-SNAPSHOT" ); + assertVersionOlder( "1.0.0-SNAPSHOT", "1.1-SNAPSHOT" ); + assertVersionOlder( "1.1-SNAPSHOT", "1.2.0-SNAPSHOT" ); + + // assertVersionOlder( "1.0-alpha-1-SNAPSHOT", "1.0-SNAPSHOT" ); + assertVersionOlder( "1.0-alpha-1-SNAPSHOT", "1.0-alpha-2-SNAPSHOT" ); + assertVersionOlder( "1.0-alpha-1-SNAPSHOT", "1.0-beta-1-SNAPSHOT" ); + + assertVersionOlder( "1.0-beta-1-SNAPSHOT", "1.0-SNAPSHOT-SNAPSHOT" ); + assertVersionOlder( "1.0-SNAPSHOT-SNAPSHOT", "1.0-SNAPSHOT" ); + assertVersionOlder( "1.0-alpha-1-SNAPSHOT-SNAPSHOT", "1.0-alpha-1-SNAPSHOT" ); + + assertVersionOlder( "1.0-SNAPSHOT", "1.0-1-SNAPSHOT" ); + assertVersionOlder( "1.0-1-SNAPSHOT", "1.0-2-SNAPSHOT" ); + // assertVersionEqual( "2.0-0-SNAPSHOT", "2.0-SNAPSHOT" ); + assertVersionOlder( "2.0-SNAPSHOT", "2.0-1-SNAPSHOT" ); + assertVersionOlder( "2.0.0-SNAPSHOT", "2.0-1-SNAPSHOT" ); + assertVersionOlder( "2.0-1-SNAPSHOT", "2.0.1-SNAPSHOT" ); + + assertVersionOlder( "2.0.1-klm-SNAPSHOT", "2.0.1-lmn-SNAPSHOT" ); + // assertVersionOlder( "2.0.1-xyz-SNAPSHOT", "2.0.1-SNAPSHOT" ); + assertVersionOlder( "2.0.1-SNAPSHOT", "2.0.1-123-SNAPSHOT" ); + assertVersionOlder( "2.0.1-xyz-SNAPSHOT", "2.0.1-123-SNAPSHOT" ); + } + + public void testSnapshotVsReleases() + { + assertVersionOlder( "1.0-RC1", "1.0-SNAPSHOT" ); + assertVersionOlder( "1.0-rc1", "1.0-SNAPSHOT" ); + assertVersionOlder( "1.0-rc-1", "1.0-SNAPSHOT" ); + } + + public void testHashCode() + { + ArtifactVersion v1 = newArtifactVersion( "1" ); + ArtifactVersion v2 = newArtifactVersion( "1.0" ); + assertEquals( true, v1.equals( v2 ) ); + assertEquals( v1.hashCode(), v2.hashCode() ); + } + + public void testEqualsNullSafe() + { + assertFalse( newArtifactVersion( "1" ).equals( null ) ); + } + + public void testEqualsTypeSafe() + { + assertFalse( newArtifactVersion( "1" ).equals( "non-an-artifact-version-instance" ) ); + } + + public void testNonNumericVersionRepresentationReturnsANumberFormatException() + { + try + { + new DefaultArtifactVersion( "..." ); + } + catch ( Exception e ) + { + assertTrue( "We expect a NumberFormatException to be thrown.", e instanceof NumberFormatException ); + } + } + + private void assertVersionOlder( String left, String right ) + { + assertTrue( left + " should be older than " + right, + newArtifactVersion( left ).compareTo( newArtifactVersion( right ) ) < 0 ); + assertTrue( right + " should be newer than " + left, + newArtifactVersion( right ).compareTo( newArtifactVersion( left ) ) > 0 ); + } + + private void assertVersionEqual( String left, String right ) + { + assertTrue( left + " should be equal to " + right, + newArtifactVersion( left ).compareTo( newArtifactVersion( right ) ) == 0 ); + assertTrue( right + " should be equal to " + left, + newArtifactVersion( right ).compareTo( newArtifactVersion( left ) ) == 0 ); + } +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/VersionRangeTest.java b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/VersionRangeTest.java new file mode 100644 index 00000000..14b16cba --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/VersionRangeTest.java @@ -0,0 +1,730 @@ +package org.apache.maven.artifact.versioning; + +/* + * 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. + */ + +import java.util.List; + +import junit.framework.TestCase; + +import org.apache.maven.artifact.Artifact; + +/** + * Tests version range construction. + * + * @author <a href="mailto:brett@apache.org">Brett Porter</a> + */ +public class VersionRangeTest + extends TestCase +{ + private static final String CHECK_NUM_RESTRICTIONS = "check number of restrictions"; + + private static final String CHECK_UPPER_BOUND = "check upper bound"; + + private static final String CHECK_UPPER_BOUND_INCLUSIVE = "check upper bound is inclusive"; + + private static final String CHECK_LOWER_BOUND = "check lower bound"; + + private static final String CHECK_LOWER_BOUND_INCLUSIVE = "check lower bound is inclusive"; + + private static final String CHECK_VERSION_RECOMMENDATION = "check version recommended"; + + private static final String CHECK_SELECTED_VERSION_KNOWN = "check selected version known"; + + private static final String CHECK_SELECTED_VERSION = "check selected version"; + + public void testRange() + throws InvalidVersionSpecificationException, OverConstrainedVersionException + { + Artifact artifact = null; + + VersionRange range = VersionRange.createFromVersionSpec( "(,1.0]" ); + List<Restriction> restrictions = range.getRestrictions(); + assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() ); + Restriction restriction = restrictions.get( 0 ); + assertNull( CHECK_LOWER_BOUND, restriction.getLowerBound() ); + assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertEquals( CHECK_UPPER_BOUND, "1.0", restriction.getUpperBound().toString() ); + assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + assertNull( CHECK_VERSION_RECOMMENDATION, range.getRecommendedVersion() ); + assertFalse( CHECK_SELECTED_VERSION_KNOWN, range.isSelectedVersionKnown( artifact ) ); + assertNull( CHECK_SELECTED_VERSION, range.getSelectedVersion( artifact ) ); + + range = VersionRange.createFromVersionSpec( "1.0" ); + assertEquals( CHECK_VERSION_RECOMMENDATION, "1.0", range.getRecommendedVersion().toString() ); + restrictions = range.getRestrictions(); + assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() ); + restriction = restrictions.get( 0 ); + assertNull( CHECK_LOWER_BOUND, restriction.getLowerBound() ); + assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertNull( CHECK_UPPER_BOUND, restriction.getUpperBound() ); + assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + assertTrue( CHECK_SELECTED_VERSION_KNOWN, range.isSelectedVersionKnown( artifact ) ); + assertEquals( CHECK_SELECTED_VERSION, "1.0", range.getSelectedVersion( artifact ).toString() ); + + range = VersionRange.createFromVersionSpec( "[1.0]" ); + restrictions = range.getRestrictions(); + assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() ); + restriction = restrictions.get( 0 ); + assertEquals( CHECK_LOWER_BOUND, "1.0", restriction.getLowerBound().toString() ); + assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertEquals( CHECK_UPPER_BOUND, "1.0", restriction.getUpperBound().toString() ); + assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + assertNull( CHECK_VERSION_RECOMMENDATION, range.getRecommendedVersion() ); + assertFalse( CHECK_SELECTED_VERSION_KNOWN, range.isSelectedVersionKnown( artifact ) ); + assertNull( CHECK_SELECTED_VERSION, range.getSelectedVersion( artifact ) ); + + range = VersionRange.createFromVersionSpec( "[1.2,1.3]" ); + restrictions = range.getRestrictions(); + assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() ); + restriction = restrictions.get( 0 ); + assertEquals( CHECK_LOWER_BOUND, "1.2", restriction.getLowerBound().toString() ); + assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertEquals( CHECK_UPPER_BOUND, "1.3", restriction.getUpperBound().toString() ); + assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + assertNull( CHECK_VERSION_RECOMMENDATION, range.getRecommendedVersion() ); + assertFalse( CHECK_SELECTED_VERSION_KNOWN, range.isSelectedVersionKnown( artifact ) ); + assertNull( CHECK_SELECTED_VERSION, range.getSelectedVersion( artifact ) ); + + range = VersionRange.createFromVersionSpec( "[1.0,2.0)" ); + restrictions = range.getRestrictions(); + assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() ); + restriction = restrictions.get( 0 ); + assertEquals( CHECK_LOWER_BOUND, "1.0", restriction.getLowerBound().toString() ); + assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertEquals( CHECK_UPPER_BOUND, "2.0", restriction.getUpperBound().toString() ); + assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + assertNull( CHECK_VERSION_RECOMMENDATION, range.getRecommendedVersion() ); + assertFalse( CHECK_SELECTED_VERSION_KNOWN, range.isSelectedVersionKnown( artifact ) ); + assertNull( CHECK_SELECTED_VERSION, range.getSelectedVersion( artifact ) ); + + range = VersionRange.createFromVersionSpec( "[1.5,)" ); + restrictions = range.getRestrictions(); + assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() ); + restriction = restrictions.get( 0 ); + assertEquals( CHECK_LOWER_BOUND, "1.5", restriction.getLowerBound().toString() ); + assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertNull( CHECK_UPPER_BOUND, restriction.getUpperBound() ); + assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + assertNull( CHECK_VERSION_RECOMMENDATION, range.getRecommendedVersion() ); + assertFalse( CHECK_SELECTED_VERSION_KNOWN, range.isSelectedVersionKnown( artifact ) ); + assertNull( CHECK_SELECTED_VERSION, range.getSelectedVersion( artifact ) ); + + range = VersionRange.createFromVersionSpec( "(,1.0],[1.2,)" ); + restrictions = range.getRestrictions(); + assertEquals( CHECK_NUM_RESTRICTIONS, 2, restrictions.size() ); + restriction = restrictions.get( 0 ); + assertNull( CHECK_LOWER_BOUND, restriction.getLowerBound() ); + assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertEquals( CHECK_UPPER_BOUND, "1.0", restriction.getUpperBound().toString() ); + assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + assertNull( CHECK_VERSION_RECOMMENDATION, range.getRecommendedVersion() ); + restriction = restrictions.get( 1 ); + assertEquals( CHECK_LOWER_BOUND, "1.2", restriction.getLowerBound().toString() ); + assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertNull( CHECK_UPPER_BOUND, restriction.getUpperBound() ); + assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + assertNull( CHECK_VERSION_RECOMMENDATION, range.getRecommendedVersion() ); + assertFalse( CHECK_SELECTED_VERSION_KNOWN, range.isSelectedVersionKnown( artifact ) ); + assertNull( CHECK_SELECTED_VERSION, range.getSelectedVersion( artifact ) ); + + range = VersionRange.createFromVersionSpec( "[1.0,)" ); + assertFalse( range.containsVersion( new DefaultArtifactVersion( "1.0-SNAPSHOT" ) ) ); + + range = VersionRange.createFromVersionSpec( "[1.0,1.1-SNAPSHOT]" ); + assertTrue( range.containsVersion( new DefaultArtifactVersion( "1.1-SNAPSHOT" ) ) ); + + range = VersionRange.createFromVersionSpec( "[5.0.9.0,5.0.10.0)" ); + assertTrue( range.containsVersion( new DefaultArtifactVersion( "5.0.9.0" ) ) ); + } + + public void testInvalidRanges() + { + checkInvalidRange( "(1.0)" ); + checkInvalidRange( "[1.0)" ); + checkInvalidRange( "(1.0]" ); + checkInvalidRange( "(1.0,1.0]" ); + checkInvalidRange( "[1.0,1.0)" ); + checkInvalidRange( "(1.0,1.0)" ); + checkInvalidRange( "[1.1,1.0]" ); + checkInvalidRange( "[1.0,1.2),1.3" ); + // overlap + checkInvalidRange( "[1.0,1.2),(1.1,1.3]" ); + // overlap + checkInvalidRange( "[1.1,1.3),(1.0,1.2]" ); + // ordering + checkInvalidRange( "(1.1,1.2],[1.0,1.1)" ); + } + + public void testIntersections() + throws InvalidVersionSpecificationException + { + VersionRange range1 = VersionRange.createFromVersionSpec( "1.0" ); + VersionRange range2 = VersionRange.createFromVersionSpec( "1.1" ); + VersionRange mergedRange = range1.restrict( range2 ); + // TODO: current policy is to retain the original version - is this correct, do we need strategies or is that handled elsewhere? +// assertEquals( CHECK_VERSION_RECOMMENDATION, "1.1", mergedRange.getRecommendedVersion().toString() ); + assertEquals( CHECK_VERSION_RECOMMENDATION, "1.0", mergedRange.getRecommendedVersion().toString() ); + List<Restriction> restrictions = mergedRange.getRestrictions(); + assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() ); + Restriction restriction = restrictions.get( 0 ); + assertNull( CHECK_LOWER_BOUND, restriction.getLowerBound() ); + assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertNull( CHECK_UPPER_BOUND, restriction.getUpperBound() ); + assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + + mergedRange = range2.restrict( range1 ); + assertEquals( CHECK_VERSION_RECOMMENDATION, "1.1", mergedRange.getRecommendedVersion().toString() ); + restrictions = mergedRange.getRestrictions(); + assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() ); + restriction = restrictions.get( 0 ); + assertNull( CHECK_LOWER_BOUND, restriction.getLowerBound() ); + assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertNull( CHECK_UPPER_BOUND, restriction.getUpperBound() ); + assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + + // TODO: test reversed restrictions on all below + range1 = VersionRange.createFromVersionSpec( "[1.0,)" ); + range2 = VersionRange.createFromVersionSpec( "1.1" ); + mergedRange = range1.restrict( range2 ); + assertEquals( CHECK_VERSION_RECOMMENDATION, "1.1", mergedRange.getRecommendedVersion().toString() ); + restrictions = mergedRange.getRestrictions(); + assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() ); + restriction = restrictions.get( 0 ); + assertEquals( CHECK_LOWER_BOUND, "1.0", restriction.getLowerBound().toString() ); + assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertNull( CHECK_UPPER_BOUND, restriction.getUpperBound() ); + assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + + range1 = VersionRange.createFromVersionSpec( "[1.1,)" ); + range2 = VersionRange.createFromVersionSpec( "1.1" ); + mergedRange = range1.restrict( range2 ); + assertEquals( CHECK_VERSION_RECOMMENDATION, "1.1", mergedRange.getRecommendedVersion().toString() ); + restrictions = mergedRange.getRestrictions(); + assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() ); + restriction = restrictions.get( 0 ); + assertEquals( CHECK_LOWER_BOUND, "1.1", restriction.getLowerBound().toString() ); + assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertNull( CHECK_UPPER_BOUND, restriction.getUpperBound() ); + assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + + range1 = VersionRange.createFromVersionSpec( "[1.1]" ); + range2 = VersionRange.createFromVersionSpec( "1.1" ); + mergedRange = range1.restrict( range2 ); + assertEquals( CHECK_VERSION_RECOMMENDATION, "1.1", mergedRange.getRecommendedVersion().toString() ); + restrictions = mergedRange.getRestrictions(); + assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() ); + restriction = restrictions.get( 0 ); + assertEquals( CHECK_LOWER_BOUND, "1.1", restriction.getLowerBound().toString() ); + assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertEquals( CHECK_UPPER_BOUND, "1.1", restriction.getLowerBound().toString() ); + assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + + range1 = VersionRange.createFromVersionSpec( "(1.1,)" ); + range2 = VersionRange.createFromVersionSpec( "1.1" ); + mergedRange = range1.restrict( range2 ); + assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + restrictions = mergedRange.getRestrictions(); + assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() ); + restriction = restrictions.get( 0 ); + assertEquals( CHECK_LOWER_BOUND, "1.1", restriction.getLowerBound().toString() ); + assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertNull( CHECK_UPPER_BOUND, restriction.getUpperBound() ); + assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + + range1 = VersionRange.createFromVersionSpec( "[1.2,)" ); + range2 = VersionRange.createFromVersionSpec( "1.1" ); + mergedRange = range1.restrict( range2 ); + assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + restrictions = mergedRange.getRestrictions(); + assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() ); + restriction = restrictions.get( 0 ); + assertEquals( CHECK_LOWER_BOUND, "1.2", restriction.getLowerBound().toString() ); + assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertNull( CHECK_UPPER_BOUND, restriction.getUpperBound() ); + assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + + range1 = VersionRange.createFromVersionSpec( "(,1.2]" ); + range2 = VersionRange.createFromVersionSpec( "1.1" ); + mergedRange = range1.restrict( range2 ); + assertEquals( CHECK_VERSION_RECOMMENDATION, "1.1", mergedRange.getRecommendedVersion().toString() ); + restrictions = mergedRange.getRestrictions(); + assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() ); + restriction = restrictions.get( 0 ); + assertNull( CHECK_LOWER_BOUND, restriction.getLowerBound() ); + assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertEquals( CHECK_UPPER_BOUND, "1.2", restriction.getUpperBound().toString() ); + assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + + range1 = VersionRange.createFromVersionSpec( "(,1.1]" ); + range2 = VersionRange.createFromVersionSpec( "1.1" ); + mergedRange = range1.restrict( range2 ); + assertEquals( CHECK_VERSION_RECOMMENDATION, "1.1", mergedRange.getRecommendedVersion().toString() ); + restrictions = mergedRange.getRestrictions(); + assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() ); + restriction = restrictions.get( 0 ); + assertNull( CHECK_LOWER_BOUND, restriction.getLowerBound() ); + assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertEquals( CHECK_UPPER_BOUND, "1.1", restriction.getUpperBound().toString() ); + assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + + range1 = VersionRange.createFromVersionSpec( "(,1.1)" ); + range2 = VersionRange.createFromVersionSpec( "1.1" ); + mergedRange = range1.restrict( range2 ); + assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + restrictions = mergedRange.getRestrictions(); + assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() ); + restriction = restrictions.get( 0 ); + assertNull( CHECK_LOWER_BOUND, restriction.getLowerBound() ); + assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertEquals( CHECK_UPPER_BOUND, "1.1", restriction.getUpperBound().toString() ); + assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + + range1 = VersionRange.createFromVersionSpec( "(,1.0]" ); + range2 = VersionRange.createFromVersionSpec( "1.1" ); + mergedRange = range1.restrict( range2 ); + assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + restrictions = mergedRange.getRestrictions(); + assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() ); + restriction = restrictions.get( 0 ); + assertNull( CHECK_LOWER_BOUND, restriction.getLowerBound() ); + assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertEquals( CHECK_UPPER_BOUND, "1.0", restriction.getUpperBound().toString() ); + assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + + range1 = VersionRange.createFromVersionSpec( "(,1.0], [1.1,)" ); + range2 = VersionRange.createFromVersionSpec( "1.2" ); + mergedRange = range1.restrict( range2 ); + assertEquals( CHECK_VERSION_RECOMMENDATION, "1.2", mergedRange.getRecommendedVersion().toString() ); + restrictions = mergedRange.getRestrictions(); + assertEquals( CHECK_NUM_RESTRICTIONS, 2, restrictions.size() ); + restriction = restrictions.get( 0 ); + assertNull( CHECK_LOWER_BOUND, restriction.getLowerBound() ); + assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertEquals( CHECK_UPPER_BOUND, "1.0", restriction.getUpperBound().toString() ); + assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + restriction = restrictions.get( 1 ); + assertEquals( CHECK_LOWER_BOUND, "1.1", restriction.getLowerBound().toString() ); + assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertNull( CHECK_UPPER_BOUND, restriction.getUpperBound() ); + assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + + range1 = VersionRange.createFromVersionSpec( "(,1.0], [1.1,)" ); + range2 = VersionRange.createFromVersionSpec( "1.0.5" ); + mergedRange = range1.restrict( range2 ); + assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + restrictions = mergedRange.getRestrictions(); + assertEquals( CHECK_NUM_RESTRICTIONS, 2, restrictions.size() ); + restriction = restrictions.get( 0 ); + assertNull( CHECK_LOWER_BOUND, restriction.getLowerBound() ); + assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertEquals( CHECK_UPPER_BOUND, "1.0", restriction.getUpperBound().toString() ); + assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + restriction = restrictions.get( 1 ); + assertEquals( CHECK_LOWER_BOUND, "1.1", restriction.getLowerBound().toString() ); + assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertNull( CHECK_UPPER_BOUND, restriction.getUpperBound() ); + assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + + range1 = VersionRange.createFromVersionSpec( "(,1.1), (1.1,)" ); + range2 = VersionRange.createFromVersionSpec( "1.1" ); + mergedRange = range1.restrict( range2 ); + assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + restrictions = mergedRange.getRestrictions(); + assertEquals( CHECK_NUM_RESTRICTIONS, 2, restrictions.size() ); + restriction = restrictions.get( 0 ); + assertNull( CHECK_LOWER_BOUND, restriction.getLowerBound() ); + assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertEquals( CHECK_UPPER_BOUND, "1.1", restriction.getUpperBound().toString() ); + assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + restriction = restrictions.get( 1 ); + assertEquals( CHECK_LOWER_BOUND, "1.1", restriction.getLowerBound().toString() ); + assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertNull( CHECK_UPPER_BOUND, restriction.getUpperBound() ); + assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + + range1 = VersionRange.createFromVersionSpec( "[1.1,1.3]" ); + range2 = VersionRange.createFromVersionSpec( "(1.1,)" ); + mergedRange = range1.restrict( range2 ); + assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + restrictions = mergedRange.getRestrictions(); + assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() ); + restriction = restrictions.get( 0 ); + assertEquals( CHECK_LOWER_BOUND, "1.1", restriction.getLowerBound().toString() ); + assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertEquals( CHECK_UPPER_BOUND, "1.3", restriction.getUpperBound().toString() ); + assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + + range1 = VersionRange.createFromVersionSpec( "(,1.3)" ); + range2 = VersionRange.createFromVersionSpec( "[1.2,1.3]" ); + mergedRange = range1.restrict( range2 ); + assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + restrictions = mergedRange.getRestrictions(); + assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() ); + restriction = restrictions.get( 0 ); + assertEquals( CHECK_LOWER_BOUND, "1.2", restriction.getLowerBound().toString() ); + assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertEquals( CHECK_UPPER_BOUND, "1.3", restriction.getUpperBound().toString() ); + assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + + range1 = VersionRange.createFromVersionSpec( "[1.1,1.3]" ); + range2 = VersionRange.createFromVersionSpec( "[1.2,)" ); + mergedRange = range1.restrict( range2 ); + assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + restrictions = mergedRange.getRestrictions(); + assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() ); + restriction = restrictions.get( 0 ); + assertEquals( CHECK_LOWER_BOUND, "1.2", restriction.getLowerBound().toString() ); + assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertEquals( CHECK_UPPER_BOUND, "1.3", restriction.getUpperBound().toString() ); + assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + + range1 = VersionRange.createFromVersionSpec( "(,1.3]" ); + range2 = VersionRange.createFromVersionSpec( "[1.2,1.4]" ); + mergedRange = range1.restrict( range2 ); + assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + restrictions = mergedRange.getRestrictions(); + assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() ); + restriction = restrictions.get( 0 ); + assertEquals( CHECK_LOWER_BOUND, "1.2", restriction.getLowerBound().toString() ); + assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertEquals( CHECK_UPPER_BOUND, "1.3", restriction.getUpperBound().toString() ); + assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + + range1 = VersionRange.createFromVersionSpec( "(1.2,1.3]" ); + range2 = VersionRange.createFromVersionSpec( "[1.1,1.4]" ); + mergedRange = range1.restrict( range2 ); + assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + restrictions = mergedRange.getRestrictions(); + assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() ); + restriction = restrictions.get( 0 ); + assertEquals( CHECK_LOWER_BOUND, "1.2", restriction.getLowerBound().toString() ); + assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertEquals( CHECK_UPPER_BOUND, "1.3", restriction.getUpperBound().toString() ); + assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + + range1 = VersionRange.createFromVersionSpec( "(1.2,1.3)" ); + range2 = VersionRange.createFromVersionSpec( "[1.1,1.4]" ); + mergedRange = range1.restrict( range2 ); + assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + restrictions = mergedRange.getRestrictions(); + assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() ); + restriction = restrictions.get( 0 ); + assertEquals( CHECK_LOWER_BOUND, "1.2", restriction.getLowerBound().toString() ); + assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertEquals( CHECK_UPPER_BOUND, "1.3", restriction.getUpperBound().toString() ); + assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + + range1 = VersionRange.createFromVersionSpec( "[1.2,1.3)" ); + range2 = VersionRange.createFromVersionSpec( "[1.1,1.4]" ); + mergedRange = range1.restrict( range2 ); + assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + restrictions = mergedRange.getRestrictions(); + assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() ); + restriction = restrictions.get( 0 ); + assertEquals( CHECK_LOWER_BOUND, "1.2", restriction.getLowerBound().toString() ); + assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertEquals( CHECK_UPPER_BOUND, "1.3", restriction.getUpperBound().toString() ); + assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + + range1 = VersionRange.createFromVersionSpec( "[1.0,1.1]" ); + range2 = VersionRange.createFromVersionSpec( "[1.1,1.4]" ); + mergedRange = range1.restrict( range2 ); + assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + restrictions = mergedRange.getRestrictions(); + assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() ); + restriction = restrictions.get( 0 ); + assertEquals( CHECK_LOWER_BOUND, "1.1", restriction.getLowerBound().toString() ); + assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertEquals( CHECK_UPPER_BOUND, "1.1", restriction.getUpperBound().toString() ); + assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + + range1 = VersionRange.createFromVersionSpec( "[1.0,1.1)" ); + range2 = VersionRange.createFromVersionSpec( "[1.1,1.4]" ); + mergedRange = range1.restrict( range2 ); + assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + restrictions = mergedRange.getRestrictions(); + assertEquals( CHECK_NUM_RESTRICTIONS, 0, restrictions.size() ); + + range1 = VersionRange.createFromVersionSpec( "[1.0,1.2],[1.3,1.5]" ); + range2 = VersionRange.createFromVersionSpec( "[1.1]" ); + mergedRange = range1.restrict( range2 ); + assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + restrictions = mergedRange.getRestrictions(); + assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() ); + restriction = restrictions.get( 0 ); + assertEquals( CHECK_LOWER_BOUND, "1.1", restriction.getLowerBound().toString() ); + assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertEquals( CHECK_UPPER_BOUND, "1.1", restriction.getUpperBound().toString() ); + assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + + range1 = VersionRange.createFromVersionSpec( "[1.0,1.2],[1.3,1.5]" ); + range2 = VersionRange.createFromVersionSpec( "[1.4]" ); + mergedRange = range1.restrict( range2 ); + assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + restrictions = mergedRange.getRestrictions(); + assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() ); + restriction = restrictions.get( 0 ); + assertEquals( CHECK_LOWER_BOUND, "1.4", restriction.getLowerBound().toString() ); + assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertEquals( CHECK_UPPER_BOUND, "1.4", restriction.getUpperBound().toString() ); + assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + + range1 = VersionRange.createFromVersionSpec( "[1.0,1.2],[1.3,1.5]" ); + range2 = VersionRange.createFromVersionSpec( "[1.1,1.4]" ); + mergedRange = range1.restrict( range2 ); + assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + restrictions = mergedRange.getRestrictions(); + assertEquals( CHECK_NUM_RESTRICTIONS, 2, restrictions.size() ); + restriction = restrictions.get( 0 ); + assertEquals( CHECK_LOWER_BOUND, "1.1", restriction.getLowerBound().toString() ); + assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertEquals( CHECK_UPPER_BOUND, "1.2", restriction.getUpperBound().toString() ); + assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + restriction = restrictions.get( 1 ); + assertEquals( CHECK_LOWER_BOUND, "1.3", restriction.getLowerBound().toString() ); + assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertEquals( CHECK_UPPER_BOUND, "1.4", restriction.getUpperBound().toString() ); + assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + + range1 = VersionRange.createFromVersionSpec( "[1.0,1.2),(1.3,1.5]" ); + range2 = VersionRange.createFromVersionSpec( "[1.1,1.4]" ); + mergedRange = range1.restrict( range2 ); + assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + restrictions = mergedRange.getRestrictions(); + assertEquals( CHECK_NUM_RESTRICTIONS, 2, restrictions.size() ); + restriction = restrictions.get( 0 ); + assertEquals( CHECK_LOWER_BOUND, "1.1", restriction.getLowerBound().toString() ); + assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertEquals( CHECK_UPPER_BOUND, "1.2", restriction.getUpperBound().toString() ); + assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + restriction = restrictions.get( 1 ); + assertEquals( CHECK_LOWER_BOUND, "1.3", restriction.getLowerBound().toString() ); + assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertEquals( CHECK_UPPER_BOUND, "1.4", restriction.getUpperBound().toString() ); + assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + + range1 = VersionRange.createFromVersionSpec( "[1.0,1.2],[1.3,1.5]" ); + range2 = VersionRange.createFromVersionSpec( "(1.1,1.4)" ); + mergedRange = range1.restrict( range2 ); + assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + restrictions = mergedRange.getRestrictions(); + assertEquals( CHECK_NUM_RESTRICTIONS, 2, restrictions.size() ); + restriction = restrictions.get( 0 ); + assertEquals( CHECK_LOWER_BOUND, "1.1", restriction.getLowerBound().toString() ); + assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertEquals( CHECK_UPPER_BOUND, "1.2", restriction.getUpperBound().toString() ); + assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + restriction = restrictions.get( 1 ); + assertEquals( CHECK_LOWER_BOUND, "1.3", restriction.getLowerBound().toString() ); + assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertEquals( CHECK_UPPER_BOUND, "1.4", restriction.getUpperBound().toString() ); + assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + + range1 = VersionRange.createFromVersionSpec( "[1.0,1.2),(1.3,1.5]" ); + range2 = VersionRange.createFromVersionSpec( "(1.1,1.4)" ); + mergedRange = range1.restrict( range2 ); + assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + restrictions = mergedRange.getRestrictions(); + assertEquals( CHECK_NUM_RESTRICTIONS, 2, restrictions.size() ); + restriction = restrictions.get( 0 ); + assertEquals( CHECK_LOWER_BOUND, "1.1", restriction.getLowerBound().toString() ); + assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertEquals( CHECK_UPPER_BOUND, "1.2", restriction.getUpperBound().toString() ); + assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + restriction = restrictions.get( 1 ); + assertEquals( CHECK_LOWER_BOUND, "1.3", restriction.getLowerBound().toString() ); + assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertEquals( CHECK_UPPER_BOUND, "1.4", restriction.getUpperBound().toString() ); + assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + + range1 = VersionRange.createFromVersionSpec( "(,1.1),(1.4,)" ); + range2 = VersionRange.createFromVersionSpec( "[1.1,1.4]" ); + mergedRange = range1.restrict( range2 ); + assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + restrictions = mergedRange.getRestrictions(); + assertEquals( CHECK_NUM_RESTRICTIONS, 0, restrictions.size() ); + + range1 = VersionRange.createFromVersionSpec( "(,1.1],[1.4,)" ); + range2 = VersionRange.createFromVersionSpec( "(1.1,1.4)" ); + mergedRange = range1.restrict( range2 ); + assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + restrictions = mergedRange.getRestrictions(); + assertEquals( CHECK_NUM_RESTRICTIONS, 0, restrictions.size() ); + + range1 = VersionRange.createFromVersionSpec( "[,1.1],[1.4,]" ); + range2 = VersionRange.createFromVersionSpec( "[1.2,1.3]" ); + mergedRange = range1.restrict( range2 ); + assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + restrictions = mergedRange.getRestrictions(); + assertEquals( CHECK_NUM_RESTRICTIONS, 0, restrictions.size() ); + + range1 = VersionRange.createFromVersionSpec( "[1.0,1.2],[1.3,1.5]" ); + range2 = VersionRange.createFromVersionSpec( "[1.1,1.4],[1.6,]" ); + mergedRange = range1.restrict( range2 ); + assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + restrictions = mergedRange.getRestrictions(); + assertEquals( CHECK_NUM_RESTRICTIONS, 2, restrictions.size() ); + restriction = restrictions.get( 0 ); + assertEquals( CHECK_LOWER_BOUND, "1.1", restriction.getLowerBound().toString() ); + assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertEquals( CHECK_UPPER_BOUND, "1.2", restriction.getUpperBound().toString() ); + assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + restriction = restrictions.get( 1 ); + assertEquals( CHECK_LOWER_BOUND, "1.3", restriction.getLowerBound().toString() ); + assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertEquals( CHECK_UPPER_BOUND, "1.4", restriction.getUpperBound().toString() ); + assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + + range1 = VersionRange.createFromVersionSpec( "[1.0,1.2],[1.3,1.5]" ); + range2 = VersionRange.createFromVersionSpec( "[1.1,1.4],[1.5,]" ); + mergedRange = range1.restrict( range2 ); + assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + restrictions = mergedRange.getRestrictions(); + assertEquals( CHECK_NUM_RESTRICTIONS, 3, restrictions.size() ); + restriction = restrictions.get( 0 ); + assertEquals( CHECK_LOWER_BOUND, "1.1", restriction.getLowerBound().toString() ); + assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertEquals( CHECK_UPPER_BOUND, "1.2", restriction.getUpperBound().toString() ); + assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + restriction = restrictions.get( 1 ); + assertEquals( CHECK_LOWER_BOUND, "1.3", restriction.getLowerBound().toString() ); + assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertEquals( CHECK_UPPER_BOUND, "1.4", restriction.getUpperBound().toString() ); + assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + restriction = restrictions.get( 2 ); + assertEquals( CHECK_LOWER_BOUND, "1.5", restriction.getLowerBound().toString() ); + assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertEquals( CHECK_UPPER_BOUND, "1.5", restriction.getUpperBound().toString() ); + assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + + range1 = VersionRange.createFromVersionSpec( "[1.0,1.2],[1.3,1.7]" ); + range2 = VersionRange.createFromVersionSpec( "[1.1,1.4],[1.5,1.6]" ); + mergedRange = range1.restrict( range2 ); + assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + restrictions = mergedRange.getRestrictions(); + assertEquals( CHECK_NUM_RESTRICTIONS, 3, restrictions.size() ); + restriction = restrictions.get( 0 ); + assertEquals( CHECK_LOWER_BOUND, "1.1", restriction.getLowerBound().toString() ); + assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertEquals( CHECK_UPPER_BOUND, "1.2", restriction.getUpperBound().toString() ); + assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + restriction = restrictions.get( 1 ); + assertEquals( CHECK_LOWER_BOUND, "1.3", restriction.getLowerBound().toString() ); + assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertEquals( CHECK_UPPER_BOUND, "1.4", restriction.getUpperBound().toString() ); + assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + restriction = restrictions.get( 2 ); + assertEquals( CHECK_LOWER_BOUND, "1.5", restriction.getLowerBound().toString() ); + assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() ); + assertEquals( CHECK_UPPER_BOUND, "1.6", restriction.getUpperBound().toString() ); + assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() ); + + // test restricting empty sets + range1 = VersionRange.createFromVersionSpec( "[,1.1],[1.4,]" ); + range2 = VersionRange.createFromVersionSpec( "[1.2,1.3]" ); + range1 = range1.restrict( range2 ); + mergedRange = range1.restrict( range2 ); + assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + restrictions = mergedRange.getRestrictions(); + assertEquals( CHECK_NUM_RESTRICTIONS, 0, restrictions.size() ); + + range1 = VersionRange.createFromVersionSpec( "[,1.1],[1.4,]" ); + range2 = VersionRange.createFromVersionSpec( "[1.2,1.3]" ); + range2 = range1.restrict( range2 ); + mergedRange = range1.restrict( range2 ); + assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() ); + restrictions = mergedRange.getRestrictions(); + assertEquals( CHECK_NUM_RESTRICTIONS, 0, restrictions.size() ); + } + + public void testReleaseRangeBoundsContainsSnapshots() + throws InvalidVersionSpecificationException + { + VersionRange range = VersionRange.createFromVersionSpec( "[1.0,1.2]" ); + + assertTrue( range.containsVersion( new DefaultArtifactVersion( "1.1-SNAPSHOT" ) ) ); + assertTrue( range.containsVersion( new DefaultArtifactVersion( "1.2-SNAPSHOT" ) ) ); + assertFalse( range.containsVersion( new DefaultArtifactVersion( "1.0-SNAPSHOT" ) ) ); + } + + public void testSnapshotRangeBoundsCanContainSnapshots() + throws InvalidVersionSpecificationException + { + VersionRange range = VersionRange.createFromVersionSpec( "[1.0,1.2-SNAPSHOT]" ); + + assertTrue( range.containsVersion( new DefaultArtifactVersion( "1.1-SNAPSHOT" ) ) ); + assertTrue( range.containsVersion( new DefaultArtifactVersion( "1.2-SNAPSHOT" ) ) ); + + range = VersionRange.createFromVersionSpec( "[1.0-SNAPSHOT,1.2]" ); + + assertTrue( range.containsVersion( new DefaultArtifactVersion( "1.0-SNAPSHOT" ) ) ); + assertTrue( range.containsVersion( new DefaultArtifactVersion( "1.1-SNAPSHOT" ) ) ); + } + + public void testSnapshotSoftVersionCanContainSnapshot() + throws InvalidVersionSpecificationException + { + VersionRange range = VersionRange.createFromVersionSpec( "1.0-SNAPSHOT" ); + + assertTrue( range.containsVersion( new DefaultArtifactVersion( "1.0-SNAPSHOT" ) ) ); + } + + private void checkInvalidRange( String version ) + { + try + { + VersionRange.createFromVersionSpec( version ); + fail( "Version " + version + " should have failed to construct" ); + } + catch ( InvalidVersionSpecificationException expected ) + { + // expected + } + } + + public void testContains() throws InvalidVersionSpecificationException + { + ArtifactVersion actualVersion = new DefaultArtifactVersion( "2.0.5" ); + assertTrue( enforceVersion( "2.0.5", actualVersion ) ); + assertTrue( enforceVersion( "2.0.4", actualVersion ) ); + assertTrue( enforceVersion( "[2.0.5]", actualVersion ) ); + assertFalse( enforceVersion( "[2.0.6,)", actualVersion ) ); + assertFalse( enforceVersion( "[2.0.6]", actualVersion ) ); + assertTrue( enforceVersion( "[2.0,2.1]", actualVersion ) ); + assertFalse( enforceVersion( "[2.0,2.0.3]", actualVersion ) ); + assertTrue( enforceVersion( "[2.0,2.0.5]", actualVersion ) ); + assertFalse( enforceVersion( "[2.0,2.0.5)", actualVersion ) ); + } + + public boolean enforceVersion( String requiredVersionRange, ArtifactVersion actualVersion ) + throws InvalidVersionSpecificationException + { + VersionRange vr = null; + + vr = VersionRange.createFromVersionSpec( requiredVersionRange ); + + return vr.containsVersion( actualVersion ); + } + + public void testOrder0() + { + // assertTrue( new DefaultArtifactVersion( "1.0-alpha10" ).compareTo( new DefaultArtifactVersion( "1.0-alpha1" ) ) > 0 ); + } +} |