2009-08-16 11 views

答えて

0

プロジェクトの生のクラスパスを取得し、その種類とパスに基づいて各Junitエントリを検索し、「間違った順序」になっている場合は未処理のクラスパスを変更して、プロジェクトに

以下のスニペットは、この例での取り扱いも例外はありません注意して、それを行うことができる方法の概要:

//get the project by name, you probably want to use another method to 
//obtain it 
IProject project = ResourcesPlugin.getWorkspace().getRoot() 
     .getProject("foo"); 
IJavaProject javaProject = JavaCore.create(project); 

IClasspathEntry[] entries = javaProject.getRawClasspath(); 

// find the JUnit 3 and Junit 4 entry index 
int junit3Index = -1; 
int junit4Index = -1; 
for (int i = 0; i < entries.length; i++) { 
    if (entries[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER) { 
     if (entries[i].getPath().equals(
       JUnitContainerInitializer.JUNIT3_PATH)) { 
      junit3Index = i; 
     } else if (entries[i].getPath().equals(
       JUnitContainerInitializer.JUNIT4_PATH)) { 
      junit4Index = i; 
     } 
    } 
} 

if (junit3Index != -1 && junit4Index != -1 
     && junit3Index > junit4Index) { 
    // swap the two entries 
    IClasspathEntry temp = entries[junit4Index]; 
    entries[junit4Index] = entries[junit3Index]; 
    entries[junit3Index] = temp; 

    //update the project with the modified path 
    javaProject.setRawClasspath(entries, new NullProgressMonitor()); 
} 
関連する問題