1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
// **********************************************************************
//
// Copyright (c) 2003-2010 ZeroC, Inc. All rights reserved.
//
// This plug-in is provided to you under the terms and conditions
// of the Eclipse Public License Version 1.0 ("EPL"). A copy of
// the EPL is available at http://www.eclipse.org/legal/epl-v10.html.
//
// **********************************************************************
package com.zeroc.slice2javaplugin.internal;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.core.ClasspathContainerInitializer;
import org.eclipse.jdt.core.IAccessRule;
import org.eclipse.jdt.core.IClasspathAttribute;
import org.eclipse.jdt.core.IClasspathContainer;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
public class IceClasspathContainerIntializer extends ClasspathContainerInitializer
{
private final static String CONTAINER_ID = "com.zeroc.Slice2JavaPlugin.ICE_FRAMEWORK";
@Override
public void initialize(IPath containerPath, IJavaProject project)
throws CoreException
{
if(containerPath.toString().equals(CONTAINER_ID))
{
Configuration c = new Configuration(project.getProject());
configure(c, project, containerPath);
}
}
public static IClasspathEntry getContainerEntry()
{
return JavaCore.newContainerEntry(new Path(CONTAINER_ID));
}
public static void reinitialize(IProject _project, Configuration c)
throws CoreException
{
IJavaProject javaProject = JavaCore.create(_project);
IPath containerPath = new Path(CONTAINER_ID);
configure(c, javaProject, containerPath);
}
private static void configure(Configuration c, IJavaProject javaProject, IPath containerPath)
throws JavaModelException
{
Path dir = new Path(c.getJarDir());
List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>();
for(String jar : c.getJars())
{
IPath path = dir.append(new Path(jar));
IClasspathEntry classpathEntry = JavaCore.newLibraryEntry(path, null, null, new IAccessRule[0], new IClasspathAttribute[0], false);
entries.add(classpathEntry);
}
IClasspathContainer container = new IceClasspathContainer(entries.toArray(new IClasspathEntry[0]), containerPath);
JavaCore.setClasspathContainer(containerPath, new IJavaProject[] { javaProject },
new IClasspathContainer[] { container }, new NullProgressMonitor());
}
public static void updateProjects(String value, List<IJavaProject> projects)
{
for(IJavaProject p : projects)
{
IPath containerPath = new Path(CONTAINER_ID);
Configuration c = new Configuration(p.getProject());
try
{
configure(c, p, containerPath);
}
catch(JavaModelException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
|