利用JNI监控CVS仓库变动,自动更新到相应目录——简化WEB小组开发(三、cvs篇)

 接下来的任务就非常简单了,就是编写各种各样的Action

这里我们更新cvs用javacvs开源包

import  org.junit.Test;
import  org.netbeans.lib.cvsclient.Client;
import  org.netbeans.lib.cvsclient.admin.StandardAdminHandler;
import  org.netbeans.lib.cvsclient.command.CommandAbortedException;
import  org.netbeans.lib.cvsclient.command.CommandException;
import  org.netbeans.lib.cvsclient.command.GlobalOptions;
import  org.netbeans.lib.cvsclient.command.update.UpdateCommand;
import  org.netbeans.lib.cvsclient.connection.AuthenticationException;
import  org.netbeans.lib.cvsclient.connection.PServerConnection;


public   class  ClientCVS  {
    
    @Test
    
public void fileSystemChanged() {
        
        CVSRoot cvsRoot 
= new CVSRoot(":pserver:wxy@192.168.10.231:/data/cvsroot/projects");
        cvsRoot.setPassword(
"wxy2007");
        
        PServerConnection c 
= new PServerConnection(cvsRoot);
        
        Client client 
= new Client(c, new StandardAdminHandler());
        client.setLocalPath(
"D:/aaa");
        
        client.getEventManager().addCVSListener(
new BaseListener());
        
        
//CheckoutCommand command = new CheckoutCommand(true,"Team-Tool");
        
        UpdateCommand command 
= new UpdateCommand();
        command.setBuildDirectories(
true);
        command.setPruneDirectories(
true);
        
        
        
try {
            client.executeCommand(command, 
new GlobalOptions());
        }
 catch (CommandAbortedException e) {
            e.printStackTrace();
        }
 catch (CommandException e) {
            e.printStackTrace();
        }
 catch (AuthenticationException e) {
            e.printStackTrace();
        }

        
    }


}


其他还应该写一些action来相互配合,比如第一次发现新的模块,则先签出,之后就更新,这些就是对这个cvs包的应用了
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,关于您的问题,我会尽力回答。在Android中,JNI可以用来与C/C++代码进行交互,我们可以利用JNI来读写SD卡。下面是一个简单的例子: 1. 首先,在您的Java代码中定义native方法: ``` public class MainActivity extends Activity { static { System.loadLibrary("native-lib"); } public native String readFromSDCard(String filePath); public native boolean writeToSDCard(String filePath, String content); } ``` 2. 然后,在您的C/C++代码中实现这些方法: ``` #include <jni.h> #include <string.h> #include <stdio.h> #include <android/log.h> JNIEXPORT jstring JNICALL Java_com_example_myapplication_MainActivity_readFromSDCard(JNIEnv *env, jobject instance, jstring filePath) { const char *path = env->GetStringUTFChars(filePath, 0); FILE *file = fopen(path, "r"); if (file == NULL) { __android_log_print(ANDROID_LOG_ERROR, "JNI", "readFromSDCard: fopen failed"); return NULL; } fseek(file, 0, SEEK_END); long size = ftell(file); fseek(file, 0, SEEK_SET); char *buffer = new char[size + 1]; fread(buffer, 1, size, file); buffer[size] = '\0'; fclose(file); env->ReleaseStringUTFChars(filePath, path); return env->NewStringUTF(buffer); } JNIEXPORT jboolean JNICALL Java_com_example_myapplication_MainActivity_writeToSDCard(JNIEnv *env, jobject instance, jstring filePath, jstring content) { const char *path = env->GetStringUTFChars(filePath, 0); const char *str = env->GetStringUTFChars(content, 0); FILE *file = fopen(path, "w"); if (file == NULL) { __android_log_print(ANDROID_LOG_ERROR, "JNI", "writeToSDCard: fopen failed"); return false; } fwrite(str, 1, strlen(str), file); fclose(file); env->ReleaseStringUTFChars(filePath, path); env->ReleaseStringUTFChars(content, str); return true; } ``` 3. 最后,在您的AndroidManifest.xml文件中添加以下权限: ``` <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> ``` 这样,您就可以在Java代码中调用这些native方法来读写SD卡了。 至于Android NDK的使用实例——增量更新实战,这是一个比较复杂的话题,如果您有相关的需求,可以提出具体的问题,我会尽力为您解答。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值