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
|
private void traverse(IResource resource) throws CoreException, JavaModelException {
if (resource instanceof IProject) {
IJavaProject jProject = JavaCore.create((IProject) resource);
if (null != jProject) {
IFolder outFolder = jProject.getProject().getFolder(getOutputFolder(jProject));
deleteLinks(outFolder);
IClasspathContainer container = JavaCore.getClasspathContainer(new Path(CONTAINER_ID), jProject); // container Maven
if (null == container) {
return; // TODO show some meaningful message that maven2 library container is missing.
}
IClasspathEntry[] classpath = container.getClasspathEntries();
for(IClasspathEntry entry : classpath) {
if(entry.getEntryKind() != IClasspathEntry.CPE_PROJECT) {
IPath iPath = entry.getPath(); // chemin absolu du jar à copier
String target = getOutputFolder(jProject) + iPath.lastSegment(); // chemin relatif du jar dans WEB-INF
IFile file = jProject.getProject().getFile(target);
System.out.println("1. " + iPath.toString()); // C:/Documents and Settings/mcn/.m2/repository/monApplication/lib/applicationsWeb/castor/0.9.6/castor-0.9.6.jar
System.out.println("2. " + getOutputFolder(jProject)); // src/main/webapp/WEB-INF/lib/
System.out.println("3. " + iPath.lastSegment()); // castor-0.9.6.jar
System.out.println("4. " + target); // src/main/webapp/WEB-INF/lib/castor-0.9.6.jar
// file.createLink(iPath, IResource.REPLACE, this.monitor); // ce qui fâche ASTK, on remplace donc par des vraies copies et plus des liens
FileInputStream fis = null;
try {
fis = new FileInputStream (iPath.toFile()); // on met le contenu du jar dans un inputStream
if (!file.exists()) {
file.create(fis, IResource.NONE, monitor); // on le crée dans le workspace
System.out.println("J'ai créé " + file.getName());
}
} catch (FileNotFoundException e) {
System.out.println ("Le fichier n'a pas été trouvé");
e.printStackTrace();
}
System.out.println("La ressource " + file.getName() + " est synchronisée = " + file.isSynchronized(IResource.DEPTH_ZERO)); // toujours à vrai
}
}
}
}
}
private void deleteLinks(IFolder outFolder) throws CoreException {
IResource[] resources = outFolder.members(IFolder.NONE);
for(IResource res : resources) {
try {
res.delete(false, monitor);
System.out.println("J'ai effacé " + res.getName());
} catch (Exception e) {
System.out.println("Exception : impossible de supprimer " + res.getName());
}
System.out.println("La ressource " + res.getName() + " est synchronisée = " + res.isSynchronized(IResource.DEPTH_ZERO)); // toujours vrai...
}
} |
Partager