You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by GitBox <gi...@apache.org> on 2020/10/06 14:17:03 UTC

[GitHub] [maven-stage-plugin] michaelboyles opened a new pull request #7: [MSTAGE-26] - Fix and un-ignore RepositoryCopierTest

michaelboyles opened a new pull request #7:
URL: https://github.com/apache/maven-stage-plugin/pull/7


   https://issues.apache.org/jira/projects/MSTAGE/issues/MSTAGE-26
   
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-stage-plugin] michaelboyles commented on a change in pull request #7: [MSTAGE-26] - Fix and un-ignore RepositoryCopierTest

Posted by GitBox <gi...@apache.org>.
michaelboyles commented on a change in pull request #7:
URL: https://github.com/apache/maven-stage-plugin/pull/7#discussion_r677800309



##########
File path: src/test/java/org/apache/maven/plugins/stage/RepositoryCopierTest.java
##########
@@ -19,46 +19,150 @@
  * under the License.
  */
 
-import org.codehaus.plexus.PlexusTestCase;
-import org.codehaus.plexus.util.FileUtils;
-import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
+import com.jcraft.jsch.JSch;
+import org.apache.commons.io.FileUtils;
+import org.apache.maven.artifact.manager.WagonManager;
 import org.apache.maven.artifact.repository.metadata.Metadata;
+import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
 import org.apache.maven.wagon.repository.Repository;
+import org.apache.sshd.common.NamedFactory;
+import org.apache.sshd.common.file.virtualfs.VirtualFileSystemFactory;
+import org.apache.sshd.common.kex.KeyExchange;
+import org.apache.sshd.common.keyprovider.AbstractFileKeyPairProvider;
+import org.apache.sshd.common.session.Session;
+import org.apache.sshd.common.session.SessionListener;
+import org.apache.sshd.common.util.SecurityUtils;
+import org.apache.sshd.server.Command;
+import org.apache.sshd.server.SshServer;
+import org.apache.sshd.server.auth.UserAuth;
+import org.apache.sshd.server.auth.UserAuthNoneFactory;
+import org.apache.sshd.server.auth.pubkey.AcceptAllPublickeyAuthenticator;
+import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider;
+import org.apache.sshd.server.scp.ScpCommandFactory;
+import org.apache.sshd.server.subsystem.sftp.SftpSubsystemFactory;
+import org.bouncycastle.jce.provider.BouncyCastleProvider;
+import org.codehaus.plexus.PlexusTestCase;
 
 import java.io.File;
-import java.io.Reader;
 import java.io.FileReader;
+import java.io.IOException;
+import java.io.Reader;
+import java.nio.file.Path;
+import java.security.Security;
+import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 
 /** @author Jason van Zyl */
 public class RepositoryCopierTest
     extends PlexusTestCase
 {
-    private String version = "2.0.6";
+    private static final int PORT = 3543;
+    private static final String STAGING_REPOSITORY = "src/test/staging-repository";
+    private static final String TARGET_REPOSITORY = "src/test/target-repository";
+    private static final String WORKING_TARGET_REPOSITORY = "src/test/working-target-repository";

Review comment:
       You're right, temp dirs are a better solution. I've changed it.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-stage-plugin] elharo commented on a change in pull request #7: [MSTAGE-26] - Fix and un-ignore RepositoryCopierTest

Posted by GitBox <gi...@apache.org>.
elharo commented on a change in pull request #7:
URL: https://github.com/apache/maven-stage-plugin/pull/7#discussion_r546027543



##########
File path: src/test/java/org/apache/maven/plugins/stage/RepositoryCopierTest.java
##########
@@ -19,46 +19,150 @@
  * under the License.
  */
 
-import org.codehaus.plexus.PlexusTestCase;
-import org.codehaus.plexus.util.FileUtils;
-import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
+import com.jcraft.jsch.JSch;
+import org.apache.commons.io.FileUtils;
+import org.apache.maven.artifact.manager.WagonManager;
 import org.apache.maven.artifact.repository.metadata.Metadata;
+import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
 import org.apache.maven.wagon.repository.Repository;
+import org.apache.sshd.common.NamedFactory;
+import org.apache.sshd.common.file.virtualfs.VirtualFileSystemFactory;
+import org.apache.sshd.common.kex.KeyExchange;
+import org.apache.sshd.common.keyprovider.AbstractFileKeyPairProvider;
+import org.apache.sshd.common.session.Session;
+import org.apache.sshd.common.session.SessionListener;
+import org.apache.sshd.common.util.SecurityUtils;
+import org.apache.sshd.server.Command;
+import org.apache.sshd.server.SshServer;
+import org.apache.sshd.server.auth.UserAuth;
+import org.apache.sshd.server.auth.UserAuthNoneFactory;
+import org.apache.sshd.server.auth.pubkey.AcceptAllPublickeyAuthenticator;
+import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider;
+import org.apache.sshd.server.scp.ScpCommandFactory;
+import org.apache.sshd.server.subsystem.sftp.SftpSubsystemFactory;
+import org.bouncycastle.jce.provider.BouncyCastleProvider;
+import org.codehaus.plexus.PlexusTestCase;
 
 import java.io.File;
-import java.io.Reader;
 import java.io.FileReader;
+import java.io.IOException;
+import java.io.Reader;
+import java.nio.file.Path;
+import java.security.Security;
+import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 
 /** @author Jason van Zyl */
 public class RepositoryCopierTest
     extends PlexusTestCase
 {
-    private String version = "2.0.6";
+    private static final int PORT = 3543;
+    private static final String STAGING_REPOSITORY = "src/test/staging-repository";
+    private static final String TARGET_REPOSITORY = "src/test/target-repository";
+    private static final String WORKING_TARGET_REPOSITORY = "src/test/working-target-repository";

Review comment:
       I'm curious why only this one is added to .gitignore. Also, if it's a temporary directory perhaps use `Files.createTempDirectory` instead of gitignoring

##########
File path: src/test/java/org/apache/maven/plugins/stage/RepositoryCopierTest.java
##########
@@ -19,46 +19,150 @@
  * under the License.
  */
 
-import org.codehaus.plexus.PlexusTestCase;
-import org.codehaus.plexus.util.FileUtils;
-import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
+import com.jcraft.jsch.JSch;
+import org.apache.commons.io.FileUtils;
+import org.apache.maven.artifact.manager.WagonManager;
 import org.apache.maven.artifact.repository.metadata.Metadata;
+import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
 import org.apache.maven.wagon.repository.Repository;
+import org.apache.sshd.common.NamedFactory;
+import org.apache.sshd.common.file.virtualfs.VirtualFileSystemFactory;
+import org.apache.sshd.common.kex.KeyExchange;
+import org.apache.sshd.common.keyprovider.AbstractFileKeyPairProvider;
+import org.apache.sshd.common.session.Session;
+import org.apache.sshd.common.session.SessionListener;
+import org.apache.sshd.common.util.SecurityUtils;
+import org.apache.sshd.server.Command;
+import org.apache.sshd.server.SshServer;
+import org.apache.sshd.server.auth.UserAuth;
+import org.apache.sshd.server.auth.UserAuthNoneFactory;
+import org.apache.sshd.server.auth.pubkey.AcceptAllPublickeyAuthenticator;
+import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider;
+import org.apache.sshd.server.scp.ScpCommandFactory;
+import org.apache.sshd.server.subsystem.sftp.SftpSubsystemFactory;
+import org.bouncycastle.jce.provider.BouncyCastleProvider;
+import org.codehaus.plexus.PlexusTestCase;
 
 import java.io.File;
-import java.io.Reader;
 import java.io.FileReader;
+import java.io.IOException;
+import java.io.Reader;
+import java.nio.file.Path;
+import java.security.Security;
+import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 
 /** @author Jason van Zyl */
 public class RepositoryCopierTest
     extends PlexusTestCase
 {
-    private String version = "2.0.6";
+    private static final int PORT = 3543;
+    private static final String STAGING_REPOSITORY = "src/test/staging-repository";
+    private static final String TARGET_REPOSITORY = "src/test/target-repository";
+    private static final String WORKING_TARGET_REPOSITORY = "src/test/working-target-repository";
+    private static final String KEY = "src/test/key";
+    private static final String version = "2.0.6";
 
-    private MetadataXpp3Reader reader = new MetadataXpp3Reader();
+    private final MetadataXpp3Reader reader = new MetadataXpp3Reader();
 
-    public void testCopy()
-        throws Exception
+    private SshServer sshd;
+
+    public void setUp() throws Exception
     {
-        RepositoryCopier copier = (RepositoryCopier) lookup( RepositoryCopier.ROLE );
+        super.setUp();
+        startFtpServer();
+        makeWorkingRepository();
+    }
 
-        File targetRepoSource = new File( getBasedir(), "src/test/target-repository" );
+    private void startFtpServer()
+    {
+        sshd = SshServer.setUpDefaultServer();
+        sshd.setPort( PORT );
+
+        Security.addProvider( new BouncyCastleProvider() );
+        AbstractFileKeyPairProvider fileKeyPairProvider = SecurityUtils.createFileKeyPairProvider();
+        fileKeyPairProvider.setFiles(
+            Collections.singletonList( new File( getBasedir(), KEY) )
+        );
+        sshd.setKeyPairProvider( fileKeyPairProvider );
+
+        sshd.setFileSystemFactory(new VirtualFileSystemFactory() {
+            @Override
+            public Path getDefaultHomeDir()
+            {
+                return serverFileSystemRoot();
+            }
+        });
+
+        List<NamedFactory<UserAuth>> userAuthFactories = new ArrayList<>();
+        userAuthFactories.add( new UserAuthNoneFactory() );
+        sshd.setUserAuthFactories( userAuthFactories );
+        sshd.setPublickeyAuthenticator( AcceptAllPublickeyAuthenticator.INSTANCE );
+
+        final ScpCommandFactory scpCommandFactory = new ScpCommandFactory();
+        scpCommandFactory.setDelegateCommandFactory( new FakeUnixCommandFactory( serverFileSystemRoot() ) );
+        sshd.setCommandFactory(scpCommandFactory);
+
+        List<NamedFactory<Command>> namedFactoryList = new ArrayList<>();
+        namedFactoryList.add( new SftpSubsystemFactory() );
+        sshd.setSubsystemFactories( namedFactoryList );
+        try
+        {
+            sshd.start();
+        }
+        catch (IOException e)
+        {
+            throw new RuntimeException(e);
+        }
+    }
 
-        File targetRepo = new File( getBasedir(), "target/target-repository" );
+    // To make clean-up easier, copy the entire target repository to a new working copy. That way, rather than worry about what
+    // modifications we might have made, we can simply delete the whole thing when we're done.
+    private void makeWorkingRepository()
+    {
+        final File prototype = new File( getBasedir(), TARGET_REPOSITORY );
+        final File workingDir = new File( getBasedir(), WORKING_TARGET_REPOSITORY );
+        try
+        {
+            FileUtils.copyDirectory( prototype, workingDir );
+        }
+        catch ( IOException e )
+        {
+            throw new RuntimeException( "Couldn't copy target repository directory", e );
+        }
+    }
 
-        System.out.println( "Copying target stage for tests ..." );
+    private void deleteWorkingRepository() throws IOException
+    {
+        FileUtils.deleteDirectory( new File( getBasedir(), WORKING_TARGET_REPOSITORY ) );
+    }
 
-        FileUtils.copyDirectoryStructure( targetRepoSource, targetRepo );
+    private Path serverFileSystemRoot()
+    {
+        return new File( getBasedir(), WORKING_TARGET_REPOSITORY ).toPath();
+    }
 
-        File stagingRepo = new File( getBasedir(), "src/test/staging-repository" );
+    public void tearDown() throws Exception
+    {
+        super.tearDown();

Review comment:
       super.tearDown should come last in the method




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-stage-plugin] michaelboyles commented on pull request #7: [MSTAGE-26] - Fix and un-ignore RepositoryCopierTest

Posted by GitBox <gi...@apache.org>.
michaelboyles commented on pull request #7:
URL: https://github.com/apache/maven-stage-plugin/pull/7#issuecomment-887835618


   I've fixed merge conflicts and addressed code review comments. Please review when you have time


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-stage-plugin] michaelboyles commented on a change in pull request #7: [MSTAGE-26] - Fix and un-ignore RepositoryCopierTest

Posted by GitBox <gi...@apache.org>.
michaelboyles commented on a change in pull request #7:
URL: https://github.com/apache/maven-stage-plugin/pull/7#discussion_r677800114



##########
File path: src/test/java/org/apache/maven/plugins/stage/RepositoryCopierTest.java
##########
@@ -19,46 +19,150 @@
  * under the License.
  */
 
-import org.codehaus.plexus.PlexusTestCase;
-import org.codehaus.plexus.util.FileUtils;
-import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
+import com.jcraft.jsch.JSch;
+import org.apache.commons.io.FileUtils;
+import org.apache.maven.artifact.manager.WagonManager;
 import org.apache.maven.artifact.repository.metadata.Metadata;
+import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
 import org.apache.maven.wagon.repository.Repository;
+import org.apache.sshd.common.NamedFactory;
+import org.apache.sshd.common.file.virtualfs.VirtualFileSystemFactory;
+import org.apache.sshd.common.kex.KeyExchange;
+import org.apache.sshd.common.keyprovider.AbstractFileKeyPairProvider;
+import org.apache.sshd.common.session.Session;
+import org.apache.sshd.common.session.SessionListener;
+import org.apache.sshd.common.util.SecurityUtils;
+import org.apache.sshd.server.Command;
+import org.apache.sshd.server.SshServer;
+import org.apache.sshd.server.auth.UserAuth;
+import org.apache.sshd.server.auth.UserAuthNoneFactory;
+import org.apache.sshd.server.auth.pubkey.AcceptAllPublickeyAuthenticator;
+import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider;
+import org.apache.sshd.server.scp.ScpCommandFactory;
+import org.apache.sshd.server.subsystem.sftp.SftpSubsystemFactory;
+import org.bouncycastle.jce.provider.BouncyCastleProvider;
+import org.codehaus.plexus.PlexusTestCase;
 
 import java.io.File;
-import java.io.Reader;
 import java.io.FileReader;
+import java.io.IOException;
+import java.io.Reader;
+import java.nio.file.Path;
+import java.security.Security;
+import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 
 /** @author Jason van Zyl */
 public class RepositoryCopierTest
     extends PlexusTestCase
 {
-    private String version = "2.0.6";
+    private static final int PORT = 3543;
+    private static final String STAGING_REPOSITORY = "src/test/staging-repository";
+    private static final String TARGET_REPOSITORY = "src/test/target-repository";
+    private static final String WORKING_TARGET_REPOSITORY = "src/test/working-target-repository";
+    private static final String KEY = "src/test/key";
+    private static final String version = "2.0.6";
 
-    private MetadataXpp3Reader reader = new MetadataXpp3Reader();
+    private final MetadataXpp3Reader reader = new MetadataXpp3Reader();
 
-    public void testCopy()
-        throws Exception
+    private SshServer sshd;
+
+    public void setUp() throws Exception
     {
-        RepositoryCopier copier = (RepositoryCopier) lookup( RepositoryCopier.ROLE );
+        super.setUp();
+        startFtpServer();
+        makeWorkingRepository();
+    }
 
-        File targetRepoSource = new File( getBasedir(), "src/test/target-repository" );
+    private void startFtpServer()
+    {
+        sshd = SshServer.setUpDefaultServer();
+        sshd.setPort( PORT );
+
+        Security.addProvider( new BouncyCastleProvider() );
+        AbstractFileKeyPairProvider fileKeyPairProvider = SecurityUtils.createFileKeyPairProvider();
+        fileKeyPairProvider.setFiles(
+            Collections.singletonList( new File( getBasedir(), KEY) )
+        );
+        sshd.setKeyPairProvider( fileKeyPairProvider );
+
+        sshd.setFileSystemFactory(new VirtualFileSystemFactory() {
+            @Override
+            public Path getDefaultHomeDir()
+            {
+                return serverFileSystemRoot();
+            }
+        });
+
+        List<NamedFactory<UserAuth>> userAuthFactories = new ArrayList<>();
+        userAuthFactories.add( new UserAuthNoneFactory() );
+        sshd.setUserAuthFactories( userAuthFactories );
+        sshd.setPublickeyAuthenticator( AcceptAllPublickeyAuthenticator.INSTANCE );
+
+        final ScpCommandFactory scpCommandFactory = new ScpCommandFactory();
+        scpCommandFactory.setDelegateCommandFactory( new FakeUnixCommandFactory( serverFileSystemRoot() ) );
+        sshd.setCommandFactory(scpCommandFactory);
+
+        List<NamedFactory<Command>> namedFactoryList = new ArrayList<>();
+        namedFactoryList.add( new SftpSubsystemFactory() );
+        sshd.setSubsystemFactories( namedFactoryList );
+        try
+        {
+            sshd.start();
+        }
+        catch (IOException e)
+        {
+            throw new RuntimeException(e);
+        }
+    }
 
-        File targetRepo = new File( getBasedir(), "target/target-repository" );
+    // To make clean-up easier, copy the entire target repository to a new working copy. That way, rather than worry about what
+    // modifications we might have made, we can simply delete the whole thing when we're done.
+    private void makeWorkingRepository()
+    {
+        final File prototype = new File( getBasedir(), TARGET_REPOSITORY );
+        final File workingDir = new File( getBasedir(), WORKING_TARGET_REPOSITORY );
+        try
+        {
+            FileUtils.copyDirectory( prototype, workingDir );
+        }
+        catch ( IOException e )
+        {
+            throw new RuntimeException( "Couldn't copy target repository directory", e );
+        }
+    }
 
-        System.out.println( "Copying target stage for tests ..." );
+    private void deleteWorkingRepository() throws IOException
+    {
+        FileUtils.deleteDirectory( new File( getBasedir(), WORKING_TARGET_REPOSITORY ) );
+    }
 
-        FileUtils.copyDirectoryStructure( targetRepoSource, targetRepo );
+    private Path serverFileSystemRoot()
+    {
+        return new File( getBasedir(), WORKING_TARGET_REPOSITORY ).toPath();
+    }
 
-        File stagingRepo = new File( getBasedir(), "src/test/staging-repository" );
+    public void tearDown() throws Exception
+    {
+        super.tearDown();

Review comment:
       Thanks, done.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org