ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
OrderEntry[] entries = rootManager.getOrderEntries();
for (OrderEntry entry : entries) {
if (entry instanceof LibraryOrderEntry) {
final LibraryOrderEntry libraryEntry = (LibraryOrderEntry)entry;
final Library library = libraryEntry.getLibrary();
// log.debug("\tEntry: " + libraryEntry.getPresentableName());
String[] sourceUrls = entry.getUrls(OrderRootType.SOURCES);
String alfrescoJarUrl = null;
String alfrescoJavaJarUrl = null;
for (String url : sourceUrls) {
// log.debug("\t\tURL: " + url);
if (alfrescoJar.matcher(url).matches())
alfrescoJarUrl = url;
if (alfrescoJavaJar.matcher(url).matches())
alfrescoJavaJarUrl = url;
}
if (null != alfrescoJarUrl) {
final String finalAlfrescoJarUrl = alfrescoJarUrl;
final String finalAlfrescoJavaJarUrl = alfrescoJavaJarUrl;
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
Library.ModifiableModel modifiableModel = null;
if (library != null) {
log.info("Updating sources for: " + libraryEntry.getPresentableName());
modifiableModel = library.getModifiableModel();
// TODO: Need to be smarter about this, may need to handle multiple
if (null != finalAlfrescoJavaJarUrl)
modifiableModel.removeRoot(finalAlfrescoJavaJarUrl, OrderRootType.SOURCES);
modifiableModel.addRoot(finalAlfrescoJarUrl + "java", OrderRootType.SOURCES);
modifiableModel.commit();