diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/factory/ArtifactFactory.java b/maven-compat/src/main/java/org/apache/maven/artifact/factory/ArtifactFactory.java index e6fd005567..48012a1fa8 100644 --- a/maven-compat/src/main/java/org/apache/maven/artifact/factory/ArtifactFactory.java +++ b/maven-compat/src/main/java/org/apache/maven/artifact/factory/ArtifactFactory.java @@ -1,22 +1,18 @@ package org.apache.maven.artifact.factory; /* - * 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. + * 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; @@ -27,73 +23,27 @@ public interface ArtifactFactory String ROLE = ArtifactFactory.class.getName(); // TODO: deprecate and chase down (probably used for copying only) - Artifact createArtifact( String groupId, - String artifactId, - String version, - String scope, - String type ); + Artifact createArtifact( String groupId, String artifactId, String version, String scope, String type ); - Artifact createArtifactWithClassifier( String groupId, - String artifactId, - String version, - String type, - String classifier ); + Artifact createArtifactWithClassifier( String groupId, String artifactId, String version, String type, String classifier ); - Artifact createDependencyArtifact( String groupId, - String artifactId, - VersionRange versionRange, - String type, - String classifier, - String scope ); + Artifact createDependencyArtifact( String groupId, String artifactId, VersionRange versionRange, String type, String classifier, String scope ); - Artifact createDependencyArtifact( String groupId, - String artifactId, - VersionRange versionRange, - String type, - String classifier, - String scope, - boolean optional ); + Artifact createDependencyArtifact( String groupId, String artifactId, VersionRange versionRange, String type, String classifier, String scope, boolean optional ); - Artifact createDependencyArtifact( String groupId, - String artifactId, - VersionRange versionRange, - String type, - String classifier, - String scope, - String inheritedScope ); + Artifact createDependencyArtifact( String groupId, String artifactId, VersionRange versionRange, String type, String classifier, String scope, String inheritedScope ); - Artifact createDependencyArtifact( String groupId, - String artifactId, - VersionRange versionRange, - String type, - String classifier, - String scope, - String inheritedScope, - boolean optional ); + Artifact createDependencyArtifact( String groupId, String artifactId, VersionRange versionRange, String type, String classifier, String scope, String inheritedScope, boolean optional ); - Artifact createBuildArtifact( String groupId, - String artifactId, - String version, - String packaging ); + Artifact createBuildArtifact( String groupId, String artifactId, String version, String packaging ); - Artifact createProjectArtifact( String groupId, - String artifactId, - String version ); + Artifact createProjectArtifact( String groupId, String artifactId, String version ); - Artifact createParentArtifact( String groupId, - String artifactId, - String version ); + Artifact createParentArtifact( String groupId, String artifactId, String version ); - Artifact createPluginArtifact( String groupId, - String artifactId, - VersionRange versionRange ); + Artifact createPluginArtifact( String groupId, String artifactId, VersionRange versionRange ); - Artifact createProjectArtifact( String groupId, - String artifactId, - String version, - String scope ); + Artifact createProjectArtifact( String groupId, String artifactId, String version, String scope ); - Artifact createExtensionArtifact( String groupId, - String artifactId, - VersionRange versionRange ); + Artifact createExtensionArtifact( String groupId, String artifactId, VersionRange versionRange ); } diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/repository/ArtifactRepositoryFactory.java b/maven-compat/src/main/java/org/apache/maven/artifact/repository/ArtifactRepositoryFactory.java index a6335d84a1..0cc24d7983 100644 --- a/maven-compat/src/main/java/org/apache/maven/artifact/repository/ArtifactRepositoryFactory.java +++ b/maven-compat/src/main/java/org/apache/maven/artifact/repository/ArtifactRepositoryFactory.java @@ -1,27 +1,20 @@ 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. + * 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 org.apache.maven.artifact.InvalidRepositoryException; import org.apache.maven.artifact.UnknownRepositoryLayoutException; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; @@ -34,35 +27,18 @@ public interface ArtifactRepositoryFactory String LOCAL_REPOSITORY_ID = "local"; - ArtifactRepository createLocalRepository( File localRepositoryDirectory ) - throws InvalidRepositoryException; - ArtifactRepositoryLayout getLayout( String layoutId ) throws UnknownRepositoryLayoutException; - ArtifactRepository createDeploymentArtifactRepository( String id, - String url, - String layoutId, - boolean uniqueVersion ) + ArtifactRepository createDeploymentArtifactRepository( String id, String url, String layoutId, boolean uniqueVersion ) throws UnknownRepositoryLayoutException; - ArtifactRepository createDeploymentArtifactRepository( String id, - String url, - ArtifactRepositoryLayout layout, - boolean uniqueVersion ); + ArtifactRepository createDeploymentArtifactRepository( String id, String url, ArtifactRepositoryLayout layout, boolean uniqueVersion ); - ArtifactRepository createArtifactRepository( String id, - String url, - String layoutId, - ArtifactRepositoryPolicy snapshots, - ArtifactRepositoryPolicy releases ) + ArtifactRepository createArtifactRepository( String id, String url, String layoutId, ArtifactRepositoryPolicy snapshots, ArtifactRepositoryPolicy releases ) throws UnknownRepositoryLayoutException; - ArtifactRepository createArtifactRepository( String id, - String url, - ArtifactRepositoryLayout repositoryLayout, - ArtifactRepositoryPolicy snapshots, - ArtifactRepositoryPolicy releases ); + ArtifactRepository createArtifactRepository( String id, String url, ArtifactRepositoryLayout repositoryLayout, ArtifactRepositoryPolicy snapshots, ArtifactRepositoryPolicy releases ); void setGlobalUpdatePolicy( String snapshotPolicy ); diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/repository/DefaultArtifactRepository.java b/maven-compat/src/main/java/org/apache/maven/artifact/repository/DefaultArtifactRepository.java index 98f77d72ad..663185afcd 100644 --- a/maven-compat/src/main/java/org/apache/maven/artifact/repository/DefaultArtifactRepository.java +++ b/maven-compat/src/main/java/org/apache/maven/artifact/repository/DefaultArtifactRepository.java @@ -45,10 +45,6 @@ public class DefaultArtifactRepository private ArtifactRepositoryPolicy releases; private boolean blacklisted; - - public DefaultArtifactRepository() - { - } /** * Create a local repository or a test repository. diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/repository/DefaultArtifactRepositoryFactory.java b/maven-compat/src/main/java/org/apache/maven/artifact/repository/DefaultArtifactRepositoryFactory.java index 43ead68a73..e7fd751f83 100644 --- a/maven-compat/src/main/java/org/apache/maven/artifact/repository/DefaultArtifactRepositoryFactory.java +++ b/maven-compat/src/main/java/org/apache/maven/artifact/repository/DefaultArtifactRepositoryFactory.java @@ -19,12 +19,9 @@ package org.apache.maven.artifact.repository; * under the License. */ -import java.io.File; -import java.net.MalformedURLException; import java.util.HashMap; import java.util.Map; -import org.apache.maven.artifact.InvalidRepositoryException; import org.apache.maven.artifact.UnknownRepositoryLayoutException; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; import org.codehaus.plexus.component.annotations.Component; @@ -83,7 +80,7 @@ public class DefaultArtifactRepositoryFactory ArtifactRepositoryLayout repositoryLayout, boolean uniqueVersion ) { - return new DefaultArtifactRepository( id, url, repositoryLayout, uniqueVersion ); + return createArtifactRepository( id, url, repositoryLayout, null, null ); } public ArtifactRepository createArtifactRepository( String id, @@ -139,7 +136,7 @@ public class DefaultArtifactRepositoryFactory releases.setChecksumPolicy( globalChecksumPolicy ); } - DefaultArtifactRepository repository = new DefaultArtifactRepository( id, url, repositoryLayout, snapshots, releases ); + ArtifactRepository repository = new MavenArtifactRepository( id, url, repositoryLayout, snapshots, releases ); repository.setBlacklisted( blacklisted ); artifactRepositories.put( id, repository ); @@ -156,30 +153,4 @@ public class DefaultArtifactRepositoryFactory { globalChecksumPolicy = checksumPolicy; } - - public ArtifactRepository createLocalRepository( File localRepositoryDirectory ) - throws InvalidRepositoryException - { - ArtifactRepositoryLayout layout = getLayout( DEFAULT_LAYOUT_ID ); - DefaultArtifactRepository repo; - try - { - repo = new DefaultArtifactRepository( LOCAL_REPOSITORY_ID, - localRepositoryDirectory.toURI() - .toURL() - .toExternalForm(), - layout, new ArtifactRepositoryPolicy(), - new ArtifactRepositoryPolicy() ); - } - catch ( MalformedURLException e ) - { - throw new InvalidRepositoryException( "Invalid local repository directory: " - + localRepositoryDirectory - + ". Cannot render URL.", LOCAL_REPOSITORY_ID, e ); - } - - repo.setBasedir( localRepositoryDirectory.getAbsolutePath() ); - - return repo; - } -} + } diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/repository/MavenArtifactRepository.java b/maven-compat/src/main/java/org/apache/maven/artifact/repository/MavenArtifactRepository.java new file mode 100644 index 0000000000..8ca6a66327 --- /dev/null +++ b/maven-compat/src/main/java/org/apache/maven/artifact/repository/MavenArtifactRepository.java @@ -0,0 +1,351 @@ +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.io.File; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.metadata.ArtifactMetadata; +import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; + +//TODO: http://jira.codehaus.org/browse/MNG-4215 +//TODO: completely separate local and remote artifact repositories +public class MavenArtifactRepository + implements ArtifactRepository +{ + public static final int UNKNOWN_PORT = -1; + + private String id; + + private String url; + + private String basedir; + + private String protocol; + + private ArtifactRepositoryLayout layout; + + private ArtifactRepositoryPolicy snapshots; + + private ArtifactRepositoryPolicy releases; + + //TODO: this should be tracked externally, not by the repository itself + private boolean blacklisted; + + public MavenArtifactRepository() + { + } + + /** + * Create a remote download repository. + * + * @param id the unique identifier of the repository + * @param url the URL of the repository + * @param layout the layout of the repository + * @param snapshots the policies to use for snapshots + * @param releases the policies to use for releases + */ + public MavenArtifactRepository( String id, String url, ArtifactRepositoryLayout layout, ArtifactRepositoryPolicy snapshots, ArtifactRepositoryPolicy releases ) + { + this.id = id; + this.url = url; + this.layout = layout; + + // + // Derive these from the URL + // + this.protocol = protocol( url ); + this.basedir = basedir( url ); + this.snapshots = snapshots; + this.releases = releases; + + if ( this.snapshots == null ) + { + this.snapshots = new ArtifactRepositoryPolicy( true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, ArtifactRepositoryPolicy.CHECKSUM_POLICY_IGNORE ); + } + + if ( this.releases == null ) + { + this.releases = new ArtifactRepositoryPolicy( true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, ArtifactRepositoryPolicy.CHECKSUM_POLICY_IGNORE ); + } + } + + public String pathOf( Artifact artifact ) + { + return layout.pathOf( artifact ); + } + + public String pathOfRemoteRepositoryMetadata( ArtifactMetadata artifactMetadata ) + { + return layout.pathOfRemoteRepositoryMetadata( artifactMetadata ); + } + + public String pathOfLocalRepositoryMetadata( ArtifactMetadata metadata, ArtifactRepository repository ) + { + return layout.pathOfLocalRepositoryMetadata( metadata, repository ); + } + + public void setLayout( ArtifactRepositoryLayout layout ) + { + this.layout = layout; + } + + public ArtifactRepositoryLayout getLayout() + { + return layout; + } + + public void setSnapshotUpdatePolicy( ArtifactRepositoryPolicy snapshots ) + { + this.snapshots = snapshots; + } + + public ArtifactRepositoryPolicy getSnapshots() + { + return snapshots; + } + + public void setReleaseUpdatePolicy( ArtifactRepositoryPolicy releases ) + { + this.releases = releases; + } + + public ArtifactRepositoryPolicy getReleases() + { + return releases; + } + + public String getKey() + { + return getId(); + } + + public boolean isBlacklisted() + { + return blacklisted; + } + + public void setBlacklisted( boolean blacklisted ) + { + this.blacklisted = blacklisted; + } + + public String toString() + { + StringBuffer sb = new StringBuffer(); + + sb.append( " id: " ).append( getId() ).append( "\n" ); + sb.append( " url: " ).append( getUrl() ).append( "\n" ); + sb.append( " layout: " ).append( layout != null ? layout.getId() : "none" ).append( "\n" ); + + if ( snapshots != null ) + { + sb.append( "snapshots: [enabled => " ).append( snapshots.isEnabled() ); + sb.append( ", update => " ).append( snapshots.getUpdatePolicy() ).append( "]\n" ); + } + + if ( releases != null ) + { + sb.append( " releases: [enabled => " ).append( releases.isEnabled() ); + sb.append( ", update => " ).append( releases.getUpdatePolicy() ).append( "]\n" ); + } + + return sb.toString(); + } + + public Artifact find( Artifact artifact ) + { + File artifactFile = new File( getBasedir(), pathOf( artifact ) ); + + // We need to set the file here or the resolver will fail with an NPE, not fully equipped to deal + // with multiple local repository implementations yet. + artifact.setFile( artifactFile ); + + if( artifactFile.exists() ) + { + artifact.setResolved( true ); + } + + return artifact; + } + + public String getId() + { + return id; + } + + public String getUrl() + { + return url; + } + + public String getBasedir() + { + return basedir; + } + + public String getProtocol() + { + return protocol; + } + + public void setId( String id ) + { + this.id = id; + } + + public void setUrl( String url ) + { + this.url = url; + } + + public void setBasedir( String basedir ) + { + this.basedir = basedir; + } + + public void setProtocol( String protocol ) + { + this.protocol = protocol; + } + + // Path Utils + + /** + * /** + * Return the protocol name. + *
+ * E.g: for input + * http://www.codehause.org this method will return http + * + * @param url the url + * @return the host name + */ + public static String protocol( final String url ) + { + final int pos = url.indexOf( ":" ); + + if ( pos == -1 ) + { + return ""; + } + return url.substring( 0, pos ).trim(); + } + + /** + * Derive the path portion of the given URL. + * + * @param url the repository URL + * @return the basedir of the repository + * @todo need to URL decode for spaces? + */ + public String basedir( String url ) + { + String retValue = null; + + if ( protocol.equalsIgnoreCase( "file" ) ) + { + retValue = url.substring( protocol.length() + 1 ); + // special case: if omitted // on protocol, keep path as is + if ( retValue.startsWith( "//" ) ) + { + retValue = retValue.substring( 2 ); + + if ( retValue.length() >= 2 && ( retValue.charAt( 1 ) == '|' || retValue.charAt( 1 ) == ':' ) ) + { + // special case: if there is a windows drive letter, then keep the original return value + retValue = retValue.charAt( 0 ) + ":" + retValue.substring( 2 ); + } + else + { + // Now we expect the host + int index = retValue.indexOf( "/" ); + if ( index >= 0 ) + { + retValue = retValue.substring( index + 1 ); + } + + // special case: if there is a windows drive letter, then keep the original return value + if ( retValue.length() >= 2 && ( retValue.charAt( 1 ) == '|' || retValue.charAt( 1 ) == ':' ) ) + { + retValue = retValue.charAt( 0 ) + ":" + retValue.substring( 2 ); + } + else if ( index >= 0 ) + { + // leading / was previously stripped + retValue = "/" + retValue; + } + } + } + + // special case: if there is a windows drive letter using |, switch to : + if ( retValue.length() >= 2 && retValue.charAt( 1 ) == '|' ) + { + retValue = retValue.charAt( 0 ) + ":" + retValue.substring( 2 ); + } + } + + if ( retValue == null ) + { + retValue = "/"; + } + return retValue.trim(); + } + + public int hashCode() + { + final int prime = 31; + int result = 1; + result = prime * result + ( ( id == null ) ? 0 : id.hashCode() ); + return result; + } + + public boolean equals( Object obj ) + { + if ( this == obj ) + { + return true; + } + if ( obj == null ) + { + return false; + } + if ( getClass() != obj.getClass() ) + { + return false; + } + + final ArtifactRepository other = (ArtifactRepository) obj; + + if ( id == null ) + { + if ( other.getId() != null ) + { + return false; + } + } + else if ( !id.equals( other.getId() ) ) + { + return false; + } + + return true; + } +} diff --git a/maven-compat/src/test/java/org/apache/maven/artifact/AbstractArtifactComponentTestCase.java b/maven-compat/src/test/java/org/apache/maven/artifact/AbstractArtifactComponentTestCase.java index 7569208ce1..c8f24f8615 100644 --- a/maven-compat/src/test/java/org/apache/maven/artifact/AbstractArtifactComponentTestCase.java +++ b/maven-compat/src/test/java/org/apache/maven/artifact/AbstractArtifactComponentTestCase.java @@ -29,6 +29,7 @@ import java.util.List; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; import org.apache.maven.artifact.repository.DefaultArtifactRepository; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; @@ -43,13 +44,15 @@ public abstract class AbstractArtifactComponentTestCase { protected ArtifactFactory artifactFactory; + protected ArtifactRepositoryFactory artifactRepositoryFactory; + @Override protected void setUp() throws Exception { super.setUp(); - - artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE ); + artifactFactory = lookup( ArtifactFactory.class); + artifactRepositoryFactory = lookup( ArtifactRepositoryFactory.class ); } @Override @@ -80,7 +83,7 @@ public abstract class AbstractArtifactComponentTestCase ArtifactRepositoryLayout repoLayout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" ); - return new DefaultArtifactRepository( "test", "file://" + f.getPath(), repoLayout ); + return artifactRepositoryFactory.createArtifactRepository( "test", "file://" + f.getPath(), repoLayout, null, null ); } protected String getRepositoryLayout() @@ -98,7 +101,7 @@ public abstract class AbstractArtifactComponentTestCase ArtifactRepositoryLayout repoLayout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" ); - return new DefaultArtifactRepository( "local", "file://" + f.getPath(), repoLayout ); + return artifactRepositoryFactory.createArtifactRepository( "local", "file://" + f.getPath(), repoLayout, null, null ); } protected ArtifactRepository remoteRepository() @@ -111,7 +114,7 @@ public abstract class AbstractArtifactComponentTestCase ArtifactRepositoryLayout repoLayout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" ); - return new DefaultArtifactRepository( "test", "file://" + f.getPath(), repoLayout, + return artifactRepositoryFactory.createArtifactRepository( "test", "file://" + f.getPath(), repoLayout, new ArtifactRepositoryPolicy(), new ArtifactRepositoryPolicy() ); } @@ -121,7 +124,7 @@ public abstract class AbstractArtifactComponentTestCase ArtifactRepositoryLayout repoLayout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" ); - return new DefaultArtifactRepository( "test", "http://foo.bar/repository", repoLayout ); + return artifactRepositoryFactory.createArtifactRepository( "test", "http://foo.bar/repository", repoLayout, null, null ); } protected void assertRemoteArtifactPresent( Artifact artifact ) diff --git a/maven-compat/src/test/java/org/apache/maven/artifact/manager/DefaultWagonManagerTest.java b/maven-compat/src/test/java/org/apache/maven/artifact/manager/DefaultWagonManagerTest.java index 3efdd208d4..75c7424a25 100644 --- a/maven-compat/src/test/java/org/apache/maven/artifact/manager/DefaultWagonManagerTest.java +++ b/maven-compat/src/test/java/org/apache/maven/artifact/manager/DefaultWagonManagerTest.java @@ -30,6 +30,7 @@ import org.apache.maven.artifact.DefaultArtifact; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.metadata.ArtifactMetadata; import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; import org.apache.maven.artifact.repository.DefaultArtifactRepository; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; @@ -62,15 +63,16 @@ public class DefaultWagonManagerTest private TransferListener transferListener = new Debug(); private ArtifactFactory artifactFactory; + + private ArtifactRepositoryFactory artifactRepositoryFactory; protected void setUp() throws Exception { super.setUp(); - - wagonManager = (DefaultWagonManager) lookup( WagonManager.class ); - - artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE ); + wagonManager = (DefaultWagonManager) lookup( WagonManager.class ); + artifactFactory = lookup( ArtifactFactory.class ); + artifactRepositoryFactory = lookup( ArtifactRepositoryFactory.class ); } @Override @@ -91,8 +93,8 @@ public class DefaultWagonManagerTest Artifact artifact = createTestPomArtifact( "target/test-data/get-missing-pom" ); List repos = new ArrayList(); - repos.add(new DefaultArtifactRepository( "repo1", "string://url1", new ArtifactRepositoryLayoutStub() )); - repos.add(new DefaultArtifactRepository( "repo2", "string://url2", new ArtifactRepositoryLayoutStub() )); + repos.add(artifactRepositoryFactory.createArtifactRepository( "repo1", "string://url1", new ArtifactRepositoryLayoutStub(), null, null )); + repos.add(artifactRepositoryFactory.createArtifactRepository( "repo2", "string://url2", new ArtifactRepositoryLayoutStub(), null, null )); StringWagon wagon = (StringWagon) wagonManager.getWagon( "string" ); wagon.addExpectedContent( repos.get(0).getLayout().pathOf( artifact ), "expected" ); @@ -259,12 +261,9 @@ public class DefaultWagonManagerTest private ArtifactRepository createStringRepo() { - ArtifactRepository repo = - new DefaultArtifactRepository( "id", "string://url", new ArtifactRepositoryLayoutStub() ); - return repo; + return artifactRepositoryFactory.createArtifactRepository( "id", "string://url", new ArtifactRepositoryLayoutStub(), null, null ); } - /** * Build an ArtifactRepository object. * @@ -274,7 +273,7 @@ public class DefaultWagonManagerTest */ private ArtifactRepository getRepo( String id, String url ) { - return new DefaultArtifactRepository( id, url, new DefaultRepositoryLayout() ); + return artifactRepositoryFactory.createArtifactRepository( id, url, new DefaultRepositoryLayout(), null, null ); } /** @@ -369,11 +368,9 @@ public class DefaultWagonManagerTest public void xtestChecksumVerification() throws Exception { - ArtifactRepositoryPolicy policy = - new ArtifactRepositoryPolicy( true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, - ArtifactRepositoryPolicy.CHECKSUM_POLICY_FAIL ); - ArtifactRepository repo = - new DefaultArtifactRepository( "id", "string://url", new ArtifactRepositoryLayoutStub(), policy, policy ); + ArtifactRepositoryPolicy policy = new ArtifactRepositoryPolicy( true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, ArtifactRepositoryPolicy.CHECKSUM_POLICY_FAIL ); + + ArtifactRepository repo = artifactRepositoryFactory.createArtifactRepository( "id", "string://url", new ArtifactRepositoryLayoutStub(), policy, policy ); Artifact artifact = new DefaultArtifact( "sample.group", "sample-art", VersionRange.createFromVersion( "1.0" ), "scope", diff --git a/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java b/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java index 7ded6f12d0..20a4acb310 100644 --- a/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java +++ b/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java @@ -32,6 +32,7 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.ArtifactUtils; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; import org.apache.maven.artifact.repository.DefaultArtifactRepository; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; import org.apache.maven.artifact.versioning.VersionRange; @@ -62,12 +63,14 @@ public class PluginParameterExpressionEvaluatorTest private static final String FS = System.getProperty( "file.separator" ); private ArtifactFactory factory; + private ArtifactRepositoryFactory artifactRepositoryFactory; public void setUp() throws Exception { super.setUp(); factory = lookup( ArtifactFactory.class ); + artifactRepositoryFactory = lookup( ArtifactRepositoryFactory.class ); } @Override @@ -343,7 +346,7 @@ public class PluginParameterExpressionEvaluatorTest createExpressionEvaluator( createDefaultProject(), null, new Properties() ); Object value = expressionEvaluator.evaluate( "${localRepository}" ); - assertEquals( "local", ( (DefaultArtifactRepository) value ).getId() ); + assertEquals( "local", ( (ArtifactRepository) value ).getId() ); } public void testTwoExpressions() @@ -398,7 +401,7 @@ public class PluginParameterExpressionEvaluatorTest { ArtifactRepositoryLayout repoLayout = lookup( ArtifactRepositoryLayout.class, "legacy" ); - ArtifactRepository repo = new DefaultArtifactRepository( "local", "target/repo", repoLayout ); + ArtifactRepository repo = artifactRepositoryFactory.createArtifactRepository( "local", "target/repo", repoLayout, null, null ); MutablePlexusContainer container = (MutablePlexusContainer) getContainer(); MavenSession session = createSession( container, repo, executionProperties ); diff --git a/maven-core/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java b/maven-core/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java index 3dff2530ad..06d9a165df 100644 --- a/maven-core/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java +++ b/maven-core/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java @@ -26,6 +26,7 @@ import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.DefaultArtifactRepository; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; import org.apache.maven.model.validation.ModelValidationResult; +import org.apache.maven.repository.RepositorySystem; import org.codehaus.plexus.PlexusTestCase; /** @@ -37,11 +38,13 @@ public abstract class AbstractMavenProjectTestCase { protected ProjectBuilder projectBuilder; + protected RepositorySystem repositorySystem; + protected void setUp() throws Exception { super.setUp(); - + if ( getContainer().hasComponent( ProjectBuilder.class, "test" ) ) { projectBuilder = lookup( ProjectBuilder.class, "test" ); @@ -51,6 +54,8 @@ public abstract class AbstractMavenProjectTestCase // default over to the main project builder... projectBuilder = lookup( ProjectBuilder.class ); } + + repositorySystem = lookup( RepositorySystem.class ); } @Override @@ -70,7 +75,9 @@ public abstract class AbstractMavenProjectTestCase @Override protected String getCustomConfigurationName() { - return AbstractMavenProjectTestCase.class.getName().replace( '.', '/' ) + ".xml"; + String name = AbstractMavenProjectTestCase.class.getName().replace( '.', '/' ) + ".xml"; + System.out.println( name ); + return name; } // ---------------------------------------------------------------------- @@ -105,7 +112,7 @@ public abstract class AbstractMavenProjectTestCase { ArtifactRepositoryLayout repoLayout = lookup( ArtifactRepositoryLayout.class, "legacy" ); - ArtifactRepository r = new DefaultArtifactRepository( "local", "file://" + getLocalRepositoryPath().getAbsolutePath(), repoLayout ); + ArtifactRepository r = repositorySystem.createArtifactRepository( "local", "file://" + getLocalRepositoryPath().getAbsolutePath(), repoLayout, null, null ); return r; } diff --git a/maven-core/src/test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java b/maven-core/src/test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java index d3feefc52f..01a7741463 100644 --- a/maven-core/src/test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java +++ b/maven-core/src/test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java @@ -111,7 +111,7 @@ public class DefaultMavenProjectBuilderTest throws Exception { ArtifactRepositoryLayout repoLayout = lookup( ArtifactRepositoryLayout.class, "legacy" ); - ArtifactRepository r = new DefaultArtifactRepository( "local", "file://" + localRepoDir.getAbsolutePath(), repoLayout ); + ArtifactRepository r = repositorySystem.createArtifactRepository( "local", "file://" + localRepoDir.getAbsolutePath(), repoLayout, null, null ); return r; } diff --git a/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java b/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java index e93c9cc3a3..65996d4e12 100644 --- a/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java +++ b/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java @@ -29,6 +29,7 @@ import org.apache.maven.artifact.repository.DefaultArtifactRepository; import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; import org.apache.maven.model.PluginExecution; import org.apache.maven.project.harness.PomTestWrapper; +import org.apache.maven.repository.RepositorySystem; import org.codehaus.plexus.PlexusTestCase; public class PomConstructionTest @@ -41,7 +42,9 @@ public class PomConstructionTest private static String BASE_MIXIN_DIR = BASE_DIR + "/resources-mixins"; private DefaultProjectBuilder projectBuilder; - + + private RepositorySystem repositorySystem; + private File testDirectory; protected void setUp() @@ -50,6 +53,7 @@ public class PomConstructionTest testDirectory = new File( getBasedir(), BASE_POM_DIR ); new File( getBasedir(), BASE_MIXIN_DIR ); projectBuilder = (DefaultProjectBuilder) lookup( ProjectBuilder.class ); + repositorySystem = lookup( RepositorySystem.class ); } @Override @@ -1671,7 +1675,7 @@ public class PomConstructionTest String localRepoUrl = System.getProperty( "maven.repo.local", System.getProperty( "user.home" ) + "/.m2/repository" ); localRepoUrl = "file://" + localRepoUrl; - config.setLocalRepository( new DefaultArtifactRepository( "local", localRepoUrl, new DefaultRepositoryLayout() ) ); + config.setLocalRepository( repositorySystem.createArtifactRepository( "local", localRepoUrl, new DefaultRepositoryLayout(), null, null ) ); config.setActiveProfileIds( Arrays.asList( profileIds ) ); config.setExecutionProperties( executionProperties ); config.setLenientValidation( lenientValidation ); diff --git a/maven-core/src/test/java/org/apache/maven/project/ProjectClasspathTest.java b/maven-core/src/test/java/org/apache/maven/project/ProjectClasspathTest.java index 7b0a90a4f7..b1766b2709 100644 --- a/maven-core/src/test/java/org/apache/maven/project/ProjectClasspathTest.java +++ b/maven-core/src/test/java/org/apache/maven/project/ProjectClasspathTest.java @@ -23,6 +23,7 @@ import java.io.File; import java.util.Iterator; import org.apache.maven.artifact.Artifact; +import org.apache.maven.repository.RepositorySystem; public class ProjectClasspathTest extends AbstractMavenProjectTestCase @@ -36,6 +37,8 @@ public class ProjectClasspathTest // the metadata source looks up the default impl, so we have to trick it getContainer().addComponent( projectBuilder, ProjectBuilder.class, "default" ); + + repositorySystem = lookup( RepositorySystem.class ); } @Override diff --git a/maven-core/src/test/java/org/apache/maven/settings/PomConstructionWithSettingsTest.java b/maven-core/src/test/java/org/apache/maven/settings/PomConstructionWithSettingsTest.java index 8c244cdd6b..d348fab09b 100644 --- a/maven-core/src/test/java/org/apache/maven/settings/PomConstructionWithSettingsTest.java +++ b/maven-core/src/test/java/org/apache/maven/settings/PomConstructionWithSettingsTest.java @@ -12,6 +12,7 @@ import org.apache.maven.project.DefaultProjectBuildingRequest; import org.apache.maven.project.ProjectBuilder; import org.apache.maven.project.ProjectBuildingRequest; import org.apache.maven.project.harness.PomTestWrapper; +import org.apache.maven.repository.RepositorySystem; import org.apache.maven.settings.io.xpp3.SettingsXpp3Reader; import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.util.IOUtil; @@ -26,6 +27,8 @@ public class PomConstructionWithSettingsTest private static String BASE_POM_DIR = BASE_DIR + "/resources-settings"; private DefaultProjectBuilder projectBuilder; + + private RepositorySystem repositorySystem; private File testDirectory; @@ -34,6 +37,7 @@ public class PomConstructionWithSettingsTest { testDirectory = new File( getBasedir(), BASE_POM_DIR ); projectBuilder = (DefaultProjectBuilder) lookup( ProjectBuilder.class ); + repositorySystem = lookup( RepositorySystem.class ); } @Override @@ -83,7 +87,7 @@ public class PomConstructionWithSettingsTest String localRepoUrl = System.getProperty( "maven.repo.local", System.getProperty( "user.home" ) + "/.m2/repository" ); localRepoUrl = "file://" + localRepoUrl; - config.setLocalRepository( new DefaultArtifactRepository( "local", localRepoUrl, new DefaultRepositoryLayout() ) ); + config.setLocalRepository( repositorySystem.createArtifactRepository( "local", localRepoUrl, new DefaultRepositoryLayout(), null, null ) ); config.setActiveProfileIds( settings.getActiveProfiles() ); return new PomTestWrapper( pomFile, projectBuilder.build( pomFile, config ) ); diff --git a/maven-repository/src/main/java/org/apache/maven/repository/DefaultMirrorBuilder.java b/maven-repository/src/main/java/org/apache/maven/repository/DefaultMirrorBuilder.java index d0f089ee37..c93aacb764 100644 --- a/maven-repository/src/main/java/org/apache/maven/repository/DefaultMirrorBuilder.java +++ b/maven-repository/src/main/java/org/apache/maven/repository/DefaultMirrorBuilder.java @@ -29,6 +29,7 @@ import java.util.Set; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; import org.apache.maven.artifact.repository.DefaultArtifactRepository; +import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.logging.Logger; @@ -60,7 +61,7 @@ public class DefaultMirrorBuilder logger.warn( "You are using a mirror that doesn't declare an element. Using \'" + id + "\' instead:\nId: " + id + "\nmirrorOf: " + mirrorOf + "\nurl: " + url + "\n" ); } - ArtifactRepository mirror = new DefaultArtifactRepository( id, url, null ); + ArtifactRepository mirror = repositoryFactory.createArtifactRepository( id, url, (ArtifactRepositoryLayout)null, null, null ); if ( !mirrors.containsKey( mirrorOf ) ) { diff --git a/maven-repository/src/main/java/org/apache/maven/repository/DelegatingLocalArtifactRepository.java b/maven-repository/src/main/java/org/apache/maven/repository/DelegatingLocalArtifactRepository.java index 2559daff1c..137ca2e6c0 100644 --- a/maven-repository/src/main/java/org/apache/maven/repository/DelegatingLocalArtifactRepository.java +++ b/maven-repository/src/main/java/org/apache/maven/repository/DelegatingLocalArtifactRepository.java @@ -23,7 +23,7 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.metadata.ArtifactMetadata; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; -import org.apache.maven.artifact.repository.DefaultArtifactRepository; +import org.apache.maven.artifact.repository.MavenArtifactRepository; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; /** @@ -31,7 +31,7 @@ import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; * and user local repository. */ public class DelegatingLocalArtifactRepository - extends DefaultArtifactRepository + extends MavenArtifactRepository { private LocalArtifactRepository buildReactor; diff --git a/maven-repository/src/main/java/org/apache/maven/repository/LocalArtifactRepository.java b/maven-repository/src/main/java/org/apache/maven/repository/LocalArtifactRepository.java index bbec08cbc2..d1e92be070 100644 --- a/maven-repository/src/main/java/org/apache/maven/repository/LocalArtifactRepository.java +++ b/maven-repository/src/main/java/org/apache/maven/repository/LocalArtifactRepository.java @@ -21,9 +21,10 @@ package org.apache.maven.repository; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.repository.DefaultArtifactRepository; +import org.apache.maven.artifact.repository.MavenArtifactRepository; public abstract class LocalArtifactRepository - extends DefaultArtifactRepository + extends MavenArtifactRepository { public static final String IDE_WORKSPACE = "ide-workspace"; diff --git a/maven-repository/src/main/java/org/apache/maven/repository/RepositorySystem.java b/maven-repository/src/main/java/org/apache/maven/repository/RepositorySystem.java index 9f09590913..3e7a5c068f 100644 --- a/maven-repository/src/main/java/org/apache/maven/repository/RepositorySystem.java +++ b/maven-repository/src/main/java/org/apache/maven/repository/RepositorySystem.java @@ -25,6 +25,8 @@ import java.util.List; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.InvalidRepositoryException; import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; +import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; import org.apache.maven.artifact.resolver.ArtifactResolutionRequest; import org.apache.maven.artifact.resolver.ArtifactResolutionResult; import org.apache.maven.model.Dependency; @@ -75,6 +77,8 @@ public interface RepositorySystem ArtifactRepository createLocalRepository( File localRepository ) throws InvalidRepositoryException; + ArtifactRepository createArtifactRepository( String id, String url, ArtifactRepositoryLayout repositoryLayout, ArtifactRepositoryPolicy snapshots, ArtifactRepositoryPolicy releases ); + /** * Calculates the effective repositories for the given input repositories. This process will essentially remove * duplicate repositories by merging them into one equivalent repository. It is worth to point out that merging does diff --git a/maven-repository/src/main/java/org/apache/maven/repository/legacy/LegacyRepositorySystem.java b/maven-repository/src/main/java/org/apache/maven/repository/legacy/LegacyRepositorySystem.java index 08769b2403..22b8fa18cc 100644 --- a/maven-repository/src/main/java/org/apache/maven/repository/legacy/LegacyRepositorySystem.java +++ b/maven-repository/src/main/java/org/apache/maven/repository/legacy/LegacyRepositorySystem.java @@ -299,6 +299,11 @@ public class LegacyRepositorySystem return artifactRepositoryFactory.createArtifactRepository( repositoryId, url, defaultArtifactRepositoryLayout, snapshotsPolicy, releasesPolicy ); } + public ArtifactRepository createArtifactRepository( String id, String url, ArtifactRepositoryLayout repositoryLayout, ArtifactRepositoryPolicy snapshots, ArtifactRepositoryPolicy releases ) + { + return artifactRepositoryFactory.createArtifactRepository( id, url, repositoryLayout, snapshots, releases ); + } + public ArtifactResolutionResult resolve( ArtifactResolutionRequest request ) { /* diff --git a/maven-repository/src/test/java/org/apache/maven/repository/MirrorProcessorTest.java b/maven-repository/src/test/java/org/apache/maven/repository/MirrorProcessorTest.java index 211fc180d0..748f9bcc83 100644 --- a/maven-repository/src/test/java/org/apache/maven/repository/MirrorProcessorTest.java +++ b/maven-repository/src/test/java/org/apache/maven/repository/MirrorProcessorTest.java @@ -1,6 +1,7 @@ package org.apache.maven.repository; import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; import org.apache.maven.artifact.repository.DefaultArtifactRepository; import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; import org.codehaus.plexus.PlexusTestCase; @@ -9,11 +10,13 @@ public class MirrorProcessorTest extends PlexusTestCase { private DefaultMirrorBuilder mirrorBuilder; + private ArtifactRepositoryFactory repositorySystem; protected void setUp() throws Exception { mirrorBuilder = (DefaultMirrorBuilder) lookup( MirrorBuilder.class ); + repositorySystem = lookup( ArtifactRepositoryFactory.class ); mirrorBuilder.clearMirrors(); } @@ -179,7 +182,7 @@ public class MirrorProcessorTest */ private ArtifactRepository getRepo( String id, String url ) { - return new DefaultArtifactRepository( id, url, new DefaultRepositoryLayout() ); + return repositorySystem.createArtifactRepository( id, url, new DefaultRepositoryLayout(), null, null ); } /**