/*******************************************************************************
* Copyright (c) 2009, 2010 Innovation Gate GmbH.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Innovation Gate GmbH - initial API and implementation
******************************************************************************/
package de.innovationgate.eclipse.wgadesigner.classpath;
import java.io.File;
import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.JavaCore;
public class DirectoryLibrarySet implements LibrarySet {
private String _id;
private String _name;
private File _location;
public DirectoryLibrarySet(String id) {
_id = id;
}
public String getName() {
return _name;
}
public void setName(String name) {
_name = name;
}
public File getLocation() {
return _location;
}
public void setLocation(File location) {
_location = location;
}
public String getId() {
return _id;
}
public IClasspathEntry[] getClasspathEntries() {
return retrieveClasspathEntries(getLocation()).toArray(new IClasspathEntry[0]);
}
public static final List<IClasspathEntry> retrieveClasspathEntries(File directory) {
List<IClasspathEntry> entryList = new ArrayList<IClasspathEntry>();
File[] libs = directory.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.toLowerCase().endsWith(".jar");
}
});
if (libs != null) {
for( File lib: libs ) {
// strip off the file extension
String ext = lib.getName().split("[.]")[1];
// now see if this archive has an associated src jar
File srcArc = new File(lib.getAbsolutePath().replace("."+ext, "-src."+ext));
Path srcPath = null;
// if the source archive exists then get the path to attach it
if( srcArc.exists()) {
srcPath = new Path(srcArc.getAbsolutePath());
}
// create a new CPE_LIBRARY type of cp entry with an attached source
// archive if it exists
entryList.add(JavaCore.newLibraryEntry(new Path(lib.getAbsolutePath()) , srcPath, new Path("/")));
}
}
return entryList;
}
public String[] getDependencies() {
return null;
}
}