Modify ivy classpath entry

时间:2015-06-15 15:00:03

标签: java eclipse eclipse-plugin ivy ivyde

In the picture below, I want

  1. Ivy settings path to NOT include ${ivyproject_loc}
  2. Property Files to NOT include ${project_loc}

Here is what I have right now. I was thinking it might be easier to remove the ivy library and add it the way I want it. I know how to add, but what is the best way to remove?

protected void changeIvyClasspath(IProject project) throws CoreException {

    if(project.hasNature(JavaCore.NATURE_ID)){
        IJavaProject jproject = JavaCore.create(project);
        IClasspathEntry[] entries = jproject.getRawClasspath();
        for (IClasspathEntry entry : entries) {
            if(entry.toString().contains("org.apache.ivyde.eclipse.cpcontainer.IVYDE_CONTAINER")){
                if(entry.toString().contains("project_loc") || entry.toString().contains("ivyproject_loc")){
                    //how to remove entry?

                    addIvyToClasspath();
                }
            }
        }
    }
}

Something else I have tried is to modify the existing settings, but it did not work.

Here is the code that attempted to do that:

protected void changeIvyClasspath(IProject project) throws CoreException {

    if(project.hasNature(JavaCore.NATURE_ID)){
        IJavaProject jproject = JavaCore.create(project);
        IClasspathEntry[] entries = jproject.getRawClasspath();
        for (IClasspathEntry entry : entries) {
            if(entry.toString().contains("org.apache.ivyde.eclipse.cpcontainer.IVYDE_CONTAINER")){
                if(entry.toString().contains("project_loc") || entry.toString().contains("ivyproject_loc")){
                    IvyClasspathContainer ivycp = IvyClasspathContainerHelper.getContainer(entry.getPath(), jproject);
                    IvyClasspathContainerConfiguration conf = new IvyClasspathContainerConfiguration(jproject, "ivy.xml", true);
                    SettingsSetup ss = conf.getIvySettingsSetup();
                    List<String> props = new ArrayList<String>();
                    props.add("project.properties");
                    props.add(".properties/eclipse.properties");
                    ss.setPropertyFiles(props);
                    conf.setIvySettingsSetup(ss);
                    ss.setIvySettingsPath(".properties/ivysettings.xml");
                    ivycp.setConf(conf);
                    ivycp.launchResolve(false, null);
                }
            }
        }
    }
}

1 个答案:

答案 0 :(得分:0)

通过该项目,您可以获取所有类路径条目。我经历了并排除了常春藤条目。然后我用正确的类路径和属性文件重新添加它们。现在,路径不包括$ {ivyproject_loc}和$ {project_loc}。

以下是代码:

protected void changeIvyClasspath(IProject project, IProgressMonitor monitor) throws CoreException {

    if(project.hasNature(JavaCore.NATURE_ID)){
        IJavaProject jproject = JavaCore.create(project);
        List<IClasspathEntry> iClasspathEntryList = new ArrayList<IClasspathEntry>();

        IClasspathEntry[] entries = jproject.getRawClasspath();
        for (IClasspathEntry entry : entries) {
            //exclude ivy.xml entries
            if (!entry.getPath().toString().contains("ivy.xml")) {
                iClasspathEntryList.add(entry);
            } 
        }

        //Add the ivy entries with the correct class path
        addIvyToClasspath(new String[] { "compile", "runtime" }, true, iClasspathEntryList, project, jproject, monitor);
        addIvyToClasspath(new String[] { "provided", "test" }, false, iClasspathEntryList, project, jproject, monitor);

        entries = iClasspathEntryList.toArray(new IClasspathEntry[iClasspathEntryList.size()]);

        jproject.setRawClasspath(entries, jproject.getOutputLocation(), null);
    }
}