diff options
Diffstat (limited to 'framework/src/maven/apache-maven-3.3.3/maven-core/src/test/java/org/apache/maven/repository')
5 files changed, 672 insertions, 0 deletions
diff --git a/framework/src/maven/apache-maven-3.3.3/maven-core/src/test/java/org/apache/maven/repository/LegacyRepositoryLayout.java b/framework/src/maven/apache-maven-3.3.3/maven-core/src/test/java/org/apache/maven/repository/LegacyRepositoryLayout.java new file mode 100644 index 00000000..77a6baef --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-core/src/test/java/org/apache/maven/repository/LegacyRepositoryLayout.java @@ -0,0 +1,89 @@ +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. + */ + +import org.apache.maven.artifact.Artifact; +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.repository.layout.ArtifactRepositoryLayout; +import org.codehaus.plexus.component.annotations.Component; + +/** + * @author jdcasey + */ +@Component(role=ArtifactRepositoryLayout.class, hint="legacy") +public class LegacyRepositoryLayout + implements ArtifactRepositoryLayout +{ + private static final String PATH_SEPARATOR = "/"; + + public String getId() + { + return "legacy"; + } + + public String pathOf( Artifact artifact ) + { + ArtifactHandler artifactHandler = artifact.getArtifactHandler(); + + StringBuilder path = new StringBuilder( 128 ); + + path.append( artifact.getGroupId() ).append( '/' ); + path.append( artifactHandler.getDirectory() ).append( '/' ); + path.append( artifact.getArtifactId() ).append( '-' ).append( artifact.getVersion() ); + + if ( artifact.hasClassifier() ) + { + path.append( '-' ).append( artifact.getClassifier() ); + } + + if ( artifactHandler.getExtension() != null && artifactHandler.getExtension().length() > 0 ) + { + path.append( '.' ).append( artifactHandler.getExtension() ); + } + + return path.toString(); + } + + public String pathOfLocalRepositoryMetadata( ArtifactMetadata metadata, + ArtifactRepository repository ) + { + return pathOfRepositoryMetadata( metadata, metadata.getLocalFilename( repository ) ); + } + + private String pathOfRepositoryMetadata( ArtifactMetadata metadata, + String filename ) + { + StringBuilder path = new StringBuilder( 128 ); + + path.append( metadata.getGroupId() ).append( PATH_SEPARATOR ).append( "poms" ).append( PATH_SEPARATOR ); + + path.append( filename ); + + return path.toString(); + } + + public String pathOfRemoteRepositoryMetadata( ArtifactMetadata metadata ) + { + return pathOfRepositoryMetadata( metadata, metadata.getRemoteFilename() ); + } + +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-core/src/test/java/org/apache/maven/repository/TestArtifactHandler.java b/framework/src/maven/apache-maven-3.3.3/maven-core/src/test/java/org/apache/maven/repository/TestArtifactHandler.java new file mode 100644 index 00000000..db1fecb5 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-core/src/test/java/org/apache/maven/repository/TestArtifactHandler.java @@ -0,0 +1,83 @@ +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. + */ + +import org.apache.maven.artifact.handler.ArtifactHandler; + +/** + * Assists unit testing. + * + * @author Benjamin Bentmann + */ +class TestArtifactHandler + implements ArtifactHandler +{ + + private String type; + + private String extension; + + public TestArtifactHandler( String type ) + { + this( type, type ); + } + + public TestArtifactHandler( String type, String extension ) + { + this.type = type; + this.extension = extension; + } + + public String getClassifier() + { + return null; + } + + public String getDirectory() + { + return getPackaging() + "s"; + } + + public String getExtension() + { + return extension; + } + + public String getLanguage() + { + return "java"; + } + + public String getPackaging() + { + return type; + } + + public boolean isAddedToClasspath() + { + return true; + } + + public boolean isIncludesDependencies() + { + return false; + } + +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-core/src/test/java/org/apache/maven/repository/TestRepositoryConnector.java b/framework/src/maven/apache-maven-3.3.3/maven-core/src/test/java/org/apache/maven/repository/TestRepositoryConnector.java new file mode 100644 index 00000000..91ace4f1 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-core/src/test/java/org/apache/maven/repository/TestRepositoryConnector.java @@ -0,0 +1,123 @@ +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. + */ + +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Collection; + +import org.codehaus.plexus.util.FileUtils; +import org.eclipse.aether.artifact.Artifact; +import org.eclipse.aether.repository.RemoteRepository; +import org.eclipse.aether.spi.connector.ArtifactDownload; +import org.eclipse.aether.spi.connector.ArtifactUpload; +import org.eclipse.aether.spi.connector.MetadataDownload; +import org.eclipse.aether.spi.connector.MetadataUpload; +import org.eclipse.aether.spi.connector.RepositoryConnector; +import org.eclipse.aether.transfer.ArtifactNotFoundException; +import org.eclipse.aether.transfer.ArtifactTransferException; + +/** + * @author Benjamin Bentmann + */ +public class TestRepositoryConnector + implements RepositoryConnector +{ + + private RemoteRepository repository; + + private File basedir; + + public TestRepositoryConnector( RemoteRepository repository ) + { + this.repository = repository; + try + { + basedir = FileUtils.toFile( new URL( repository.getUrl() ) ); + } + catch ( MalformedURLException e ) + { + throw new IllegalStateException( e ); + } + } + + public void close() + { + } + + public void get( Collection<? extends ArtifactDownload> artifactDownloads, + Collection<? extends MetadataDownload> metadataDownloads ) + { + if ( artifactDownloads != null ) + { + for ( ArtifactDownload download : artifactDownloads ) + { + File remoteFile = new File( basedir, path( download.getArtifact() ) ); + try + { + FileUtils.copyFile( remoteFile, download.getFile() ); + } + catch ( IOException e ) + { + if ( !remoteFile.exists() ) + { + download.setException( new ArtifactNotFoundException( download.getArtifact(), repository ) ); + } + else + { + download.setException( new ArtifactTransferException( download.getArtifact(), repository, e ) ); + } + } + } + } + } + + private String path( Artifact artifact ) + { + StringBuilder path = new StringBuilder( 128 ); + + path.append( artifact.getGroupId().replace( '.', '/' ) ).append( '/' ); + + path.append( artifact.getArtifactId() ).append( '/' ); + + path.append( artifact.getBaseVersion() ).append( '/' ); + + path.append( artifact.getArtifactId() ).append( '-' ).append( artifact.getVersion() ); + + if ( artifact.getClassifier().length() > 0 ) + { + path.append( '-' ).append( artifact.getClassifier() ); + } + + path.append( '.' ).append( artifact.getExtension() ); + + return path.toString(); + } + + public void put( Collection<? extends ArtifactUpload> artifactUploads, + Collection<? extends MetadataUpload> metadataUploads ) + { + // TODO Auto-generated method stub + + } + +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-core/src/test/java/org/apache/maven/repository/TestRepositoryConnectorFactory.java b/framework/src/maven/apache-maven-3.3.3/maven-core/src/test/java/org/apache/maven/repository/TestRepositoryConnectorFactory.java new file mode 100644 index 00000000..17fd43f9 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-core/src/test/java/org/apache/maven/repository/TestRepositoryConnectorFactory.java @@ -0,0 +1,48 @@ +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. + */ + +import org.codehaus.plexus.component.annotations.Component; +import org.eclipse.aether.RepositorySystemSession; +import org.eclipse.aether.repository.RemoteRepository; +import org.eclipse.aether.spi.connector.RepositoryConnector; +import org.eclipse.aether.spi.connector.RepositoryConnectorFactory; +import org.eclipse.aether.transfer.NoRepositoryConnectorException; + +/** + * @author Benjamin Bentmann + */ +@Component( role = RepositoryConnectorFactory.class, hint = "test" ) +public class TestRepositoryConnectorFactory + implements RepositoryConnectorFactory +{ + + public RepositoryConnector newInstance( RepositorySystemSession session, RemoteRepository repository ) + throws NoRepositoryConnectorException + { + return new TestRepositoryConnector( repository ); + } + + public float getPriority() + { + return 0; + } + +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-core/src/test/java/org/apache/maven/repository/TestRepositorySystem.java b/framework/src/maven/apache-maven-3.3.3/maven-core/src/test/java/org/apache/maven/repository/TestRepositorySystem.java new file mode 100644 index 00000000..c4afc7a9 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-core/src/test/java/org/apache/maven/repository/TestRepositorySystem.java @@ -0,0 +1,329 @@ +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. + */ + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.DefaultArtifact; +import org.apache.maven.artifact.InvalidRepositoryException; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; +import org.apache.maven.artifact.repository.MavenArtifactRepository; +import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; +import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; +import org.apache.maven.artifact.resolver.ArtifactResolutionRequest; +import org.apache.maven.artifact.resolver.ArtifactResolutionResult; +import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; +import org.apache.maven.artifact.versioning.VersionRange; +import org.apache.maven.model.Dependency; +import org.apache.maven.model.Model; +import org.apache.maven.model.Plugin; +import org.apache.maven.model.Repository; +import org.apache.maven.model.io.ModelReader; +import org.apache.maven.project.artifact.ArtifactWithDependencies; +import org.apache.maven.settings.Mirror; +import org.apache.maven.settings.Proxy; +import org.apache.maven.settings.Server; +import org.codehaus.plexus.component.annotations.Component; +import org.codehaus.plexus.component.annotations.Requirement; +import org.codehaus.plexus.util.FileUtils; +import org.codehaus.plexus.util.StringUtils; +import org.eclipse.aether.RepositorySystemSession; + +/** + * @author Benjamin Bentmann + */ +@Component( role = RepositorySystem.class ) +public class TestRepositorySystem + implements RepositorySystem +{ + + @Requirement + private ModelReader modelReader; + + @Requirement + private ArtifactFactory artifactFactory; + + public ArtifactRepository buildArtifactRepository( Repository repository ) + throws InvalidRepositoryException + { + return new MavenArtifactRepository( repository.getId(), repository.getUrl(), new DefaultRepositoryLayout(), + new ArtifactRepositoryPolicy(), new ArtifactRepositoryPolicy() ); + } + + public Artifact createArtifact( String groupId, String artifactId, String version, String packaging ) + { + return createArtifact( groupId, artifactId, version, null, packaging ); + } + + public Artifact createArtifact( String groupId, String artifactId, String version, String scope, String type ) + { + return new DefaultArtifact( groupId, artifactId, version, scope, type, null, new TestArtifactHandler( type ) ); + } + + public ArtifactRepository createArtifactRepository( String id, String url, + ArtifactRepositoryLayout repositoryLayout, + ArtifactRepositoryPolicy snapshots, + ArtifactRepositoryPolicy releases ) + { + return new MavenArtifactRepository( id, url, repositoryLayout, snapshots, releases ); + } + + public Artifact createArtifactWithClassifier( String groupId, String artifactId, String version, String type, + String classifier ) + { + return new DefaultArtifact( groupId, artifactId, version, null, type, classifier, + new TestArtifactHandler( type ) ); + } + + public ArtifactRepository createDefaultLocalRepository() + throws InvalidRepositoryException + { + return createLocalRepository( new File( System.getProperty( "basedir", "" ), "target/local-repo" ).getAbsoluteFile() ); + } + + public ArtifactRepository createDefaultRemoteRepository() + throws InvalidRepositoryException + { + return new MavenArtifactRepository( DEFAULT_REMOTE_REPO_ID, "file://" + + new File( System.getProperty( "basedir", "" ), "src/test/remote-repo" ).toURI().getPath(), + new DefaultRepositoryLayout(), new ArtifactRepositoryPolicy(), + new ArtifactRepositoryPolicy() ); + } + + public Artifact createDependencyArtifact( Dependency dependency ) + { + Artifact artifact = + new DefaultArtifact( dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion(), + dependency.getScope(), dependency.getType(), dependency.getClassifier(), + new TestArtifactHandler( dependency.getType() ) ); + + if ( Artifact.SCOPE_SYSTEM.equals( dependency.getScope() ) ) + { + artifact.setFile( new File( dependency.getSystemPath() ) ); + artifact.setResolved( true ); + } + + return artifact; + } + + public ArtifactRepository createLocalRepository( File localRepository ) + throws InvalidRepositoryException + { + return new MavenArtifactRepository( DEFAULT_LOCAL_REPO_ID, "file://" + localRepository.toURI().getPath(), + new DefaultRepositoryLayout(), new ArtifactRepositoryPolicy(), + new ArtifactRepositoryPolicy() ); + } + + public Artifact createPluginArtifact( Plugin plugin ) + { + VersionRange versionRange; + try + { + String version = plugin.getVersion(); + if ( StringUtils.isEmpty( version ) ) + { + version = "RELEASE"; + } + versionRange = VersionRange.createFromVersionSpec( version ); + } + catch ( InvalidVersionSpecificationException e ) + { + return null; + } + + return artifactFactory.createPluginArtifact( plugin.getGroupId(), plugin.getArtifactId(), versionRange ); + } + + public Artifact createProjectArtifact( String groupId, String artifactId, String version ) + { + return createArtifact( groupId, artifactId, version, "pom" ); + } + + public List<ArtifactRepository> getEffectiveRepositories( List<ArtifactRepository> repositories ) + { + return repositories; + } + + public Mirror getMirror( ArtifactRepository repository, List<Mirror> mirrors ) + { + return null; + } + + public void injectAuthentication( List<ArtifactRepository> repositories, List<Server> servers ) + { + } + + public void injectMirror( List<ArtifactRepository> repositories, List<Mirror> mirrors ) + { + } + + public void injectProxy( List<ArtifactRepository> repositories, List<Proxy> proxies ) + { + } + + public void publish( ArtifactRepository repository, File source, String remotePath, + ArtifactTransferListener transferListener ) + throws ArtifactTransferFailedException + { + // TODO Auto-generated method stub + + } + + public ArtifactResolutionResult resolve( ArtifactResolutionRequest request ) + { + ArtifactResolutionResult result = new ArtifactResolutionResult(); + + if ( request.isResolveRoot() ) + { + try + { + resolve( request.getArtifact(), request ); + result.addArtifact( request.getArtifact() ); + } + catch ( IOException e ) + { + result.addMissingArtifact( request.getArtifact() ); + } + } + + if ( request.isResolveTransitively() ) + { + Map<String, Artifact> artifacts = new LinkedHashMap<String, Artifact>(); + + if ( request.getArtifactDependencies() != null ) + { + for ( Artifact artifact : request.getArtifactDependencies() ) + { + artifacts.put( artifact.getDependencyConflictId(), artifact ); + } + } + + List<Dependency> dependencies = new ArrayList<Dependency>(); + if ( request.getArtifact() instanceof ArtifactWithDependencies ) + { + dependencies = ( (ArtifactWithDependencies) request.getArtifact() ).getDependencies(); + } + else + { + Artifact pomArtifact = + createProjectArtifact( request.getArtifact().getGroupId(), request.getArtifact().getArtifactId(), + request.getArtifact().getVersion() ); + File pomFile = + new File( request.getLocalRepository().getBasedir(), + request.getLocalRepository().pathOf( pomArtifact ) ); + + try + { + Model model = modelReader.read( pomFile, null ); + + dependencies = model.getDependencies(); + } + catch ( IOException e ) + { + e.printStackTrace(); + } + } + + for ( Dependency dependency : dependencies ) + { + Artifact artifact = createDependencyArtifact( dependency ); + if ( !artifacts.containsKey( artifact.getDependencyConflictId() ) ) + { + artifacts.put( artifact.getDependencyConflictId(), artifact ); + } + } + + for ( Artifact artifact : artifacts.values() ) + { + try + { + resolve( artifact, request ); + result.addArtifact( artifact ); + } + catch ( IOException e ) + { + result.addMissingArtifact( artifact ); + } + } + } + + return result; + } + + private void resolve( Artifact artifact, ArtifactResolutionRequest request ) + throws IOException + { + if ( Artifact.SCOPE_SYSTEM.equals( artifact.getScope() ) ) + { + return; + } + + ArtifactRepository localRepo = request.getLocalRepository(); + + File localFile = new File( localRepo.getBasedir(), localRepo.pathOf( artifact ) ); + + artifact.setFile( localFile ); + + if ( !localFile.exists() ) + { + if ( request.getRemoteRepositories().isEmpty() ) + { + throw new IOException( localFile + " does not exist and no remote repositories are configured" ); + } + + ArtifactRepository remoteRepo = request.getRemoteRepositories().get( 0 ); + + File remoteFile = new File( remoteRepo.getBasedir(), remoteRepo.pathOf( artifact ) ); + + FileUtils.copyFile( remoteFile, localFile ); + } + + artifact.setResolved( true ); + } + + public void retrieve( ArtifactRepository repository, File destination, String remotePath, + ArtifactTransferListener transferListener ) + throws ArtifactTransferFailedException, ArtifactDoesNotExistException + { + // TODO Auto-generated method stub + + } + + public void injectMirror( RepositorySystemSession session, List<ArtifactRepository> repositories ) + { + } + + public void injectProxy( RepositorySystemSession session, List<ArtifactRepository> repositories ) + { + } + + public void injectAuthentication( RepositorySystemSession session, List<ArtifactRepository> repositories ) + { + } + +} |