Hello,
I am working on developing a plugin that allows me approve or deny events on the repository that come from pull, fetch, or clone operations. The ScmRequestCheck provides me with a
public boolean check( @Nonnull ScmRequest scmRequest ) throws IOException
where I can check whether the scmRequest is a write or a read from the repository.
So far I have the following
public class PullEventHandler implements ScmRequestCheck {
private final RefService refService;
private final ContentService contentService;
class ContentTreeCallBackImpl extends AbstractContentTreeCallback {
List<String> files = new ArrayList<>();
ContentTreeSummary fileSummary;
@Override
public boolean onTreeNode( @Nonnull ContentTreeNode node ) throws IOException {
System.out.println( "1. Name of Node: " + node.getPath() );
files.add( node.getPath().toString() );
return super.onTreeNode( node );
}
public List<String> getFiles() {
return files;
}
}
public PullEventHandler( @ComponentImport RefService refService,
@ComponentImport ContentService contentService ) {
this.refService = refService;
this.contentService = contentService;
}
@Override
public boolean check( @Nonnull ScmRequest scmRequest ) throws IOException {
if ( scmRequest.isWrite() ) {
return true;
}
return verifyFilesInRequest( scmRequest );
}
private boolean verifyFilesInRequest( ScmRequest scmRequest ) {
RepositoryBranchesRequest repositoryBranchesRequest = new RepositoryBranchesRequest.Builder( scmRequest.
getRepository() ).build();
PageRequest pageRequest = new PageRequestImpl();
Page<Branch> branches = refService.getBranches( repositoryBranchesRequest, pageRequest );
Repository repo = scmRequest.getRepository();
AbstractContentTreeCallback callBack = new ContentTreeCallBackImpl();
branches.stream().forEach( branch -> contentService.streamDirectory( repo, branch.getId(), "", true,
callBack, pageRequest ) );
File logFile = new File( "C:\\Users\\<user>\\Documents\\Dev\\atlassian\\log.txt" );
FileOutputStream fos = null;
try {
fos = new FileOutputStream( logFile );
} catch ( FileNotFoundException ex ) {
System.out.println( ex.getLocalizedMessage() );
}
for ( String path : ( ( ContentTreeCallBackImpl ) callBack ).getFiles() ) {
try {
byte[] buff = new byte[4096];
FileInputStream fis = new FileInputStream( new File( path ) );
int len;
while ( ( len = ( fis.read() ) ) > 0 ) {
fis.read( buff, 0, len );
}
fos.write( buff );
} catch ( Exception e ) {
System.out.println( e.getLocalizedMessage() );
}
}
try {
fos.close();
} catch ( IOException ex ) {
System.out.println( ex.getLocalizedMessage() );
}
return true;
}
}
when I execute my code above on the test server, I receieve the following errors:
[INFO] An error occurred while executing an external process: add_file\add_file.txt (The system cannot find the path specified)
[INFO] An error occurred while executing an external process: basic_branching\file.txt (The system cannot find the path specified)
[INFO] An error occurred while executing an external process: binary\B.zip (The system cannot find the path specified)
[INFO] An error occurred while executing an external process: binary\C.zip (The system cannot find the path specified)
[INFO] An error occurred while executing an external process: binary\D.zip (The system cannot find the path specified)
[INFO] An error occurred while executing an external process: branch_mod_merge\file.txt (The system cannot find the path specified)
[INFO] An error occurred while executing an external process: modification\mod_file.txt (The system cannot find the path specified)
[INFO] An error occurred while executing an external process: moved_dir\file.txt (The system cannot find the path specified)
[INFO] An error occurred while executing an external process: mv_file\moved_file.txt (The system cannot find the path specified)
[INFO] An error occurred while executing an external process: out_of_order\file.txt (The system cannot find the path specified)
[INFO] An error occurred while executing an external process: symlink\link.txt (The system cannot find the path specified)
[INFO] An error occurred while executing an external process: symlink\target.txt (The system cannot find the path specified)
[INFO] An error occurred while executing an external process: add_file\add_file.txt (The system cannot find the path specified)
[INFO] An error occurred while executing an external process: basic_branching\file.txt (The system cannot find the path specified)
[INFO] An error occurred while executing an external process: branch_mod_merge\file.txt (The system cannot find the path specified)
[INFO] An error occurred while executing an external process: modification\mod_file.txt (The system cannot find the path specified)
[INFO] An error occurred while executing an external process: moved_dir\file.txt (The system cannot find the path specified)
[INFO] 2019-08-02 10:57:16,553 WARN [Caesium-1-3] c.a.a.c.h.r.RemoteHashingInstructionsReader Unable to read remote instructions with key 'uid.onewayhash'.
[INFO] 2019-08-02 10:57:16,553 WARN [Caesium-1-3] c.a.a.c.h.BcryptAnalyticsEmailHasher No instructions for hashing could be found.
[INFO] An error occurred while executing an external process: mv_file\moved_file.txt (The system cannot find the path specified)
[INFO] An error occurred while executing an external process: out_of_order\file.txt (The system cannot find the path specified)
[INFO] An error occurred while executing an external process: symlink\link.txt (The system cannot find the path specified)
[INFO] An error occurred while executing an external process: symlink\target.txt (The system cannot find the path specified)
[INFO] An error occurred while executing an external process: add_file\add_file.txt (The system cannot find the path specified)
[INFO] An error occurred while executing an external process: basic_branching\file.txt (The system cannot find the path specified)
[INFO] An error occurred while executing an external process: modification\mod_file.txt (The system cannot find the path specified)
[INFO] An error occurred while executing an external process: moved_dir\file.txt (The system cannot find the path specified)
[INFO] An error occurred while executing an external process: mv_file\moved_file.txt (The system cannot find the path specified)
[INFO] An error occurred while executing an external process: out_of_order\file.txt (The system cannot find the path specified)
[INFO] An error occurred while executing an external process: symlink\link.txt (The system cannot find the path specified)
[INFO] An error occurred while executing an external process: symlink\target.txt (The system cannot find the path specified)
[INFO] An error occurred while executing an external process: out_of_order\file.txt (The system cannot find the path specified)
I have been at this for a few days now and I cant find anything specific to my case.
Any help is appreciated.