Eclipse Public License - v 1.0
THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECI...
If you think the Android project m2e-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/*******************************************************************************
* Copyright (c) 2013 Ricardo Gladwell/*www.java2s.com*/
* 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
*******************************************************************************/package me.gladwell.eclipse.m2e.android.configuration;
importstatic com.google.common.base.Predicates.and;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.m2e.jdt.IClasspathDescriptor;
import org.eclipse.m2e.jdt.IClasspathEntryDescriptor;
import com.google.common.base.Predicate;
publicclass Classpaths {
private Classpaths() {
}
publicstatic IClasspathEntry findContainerMatching(final IClasspathDescriptor classpath, final String path) {
return matchContainer(classpath, new Predicate<IClasspathEntry>() {
publicboolean apply(IClasspathEntry entry) {
return entry.getPath().toOSString().equals(path);
}
});
}
publicstatic IClasspathEntry findContainerContaining(final IClasspathDescriptor classpath, final String fragment) {
return matchContainer(classpath, new Predicate<IClasspathEntry>() {
publicboolean apply(IClasspathEntry entry) {
return entry.getPath().toOSString().contains(fragment);
}
});
}
publicstatic IClasspathEntry findSourceEntry(IClasspathEntry[] classpath, final String path) {
return matchEntry(classpath, and(entryOfType(IClasspathEntry.CPE_SOURCE), new Predicate<IClasspathEntry>() {
publicboolean apply(IClasspathEntry entry) {
return entry.getPath().toOSString().endsWith(path);
}
}));
}
privatestatic IClasspathEntry matchContainer(IClasspathDescriptor classpath, Predicate<IClasspathEntry> predicate) {
return matchEntry(classpath.getEntries(), and(entryOfType(IClasspathEntry.CPE_CONTAINER), predicate));
}
privatestatic Predicate<IClasspathEntry> entryOfType(finalint type) {
returnnew Predicate<IClasspathEntry>() {
publicboolean apply(IClasspathEntry entry) {
return entry.getEntryKind() == type;
}
};
}
privatestatic IClasspathEntry matchEntry(IClasspathEntry[] classpath, Predicate<IClasspathEntry> predicate) {
for (IClasspathEntry entry : classpath) {
if (predicate.apply(entry)) {
return entry;
}
}
return null;
}
publicstatic IClasspathEntryDescriptor findSourceEntryDescriptor(IClasspathDescriptor classpath, String path) {
for (IClasspathEntryDescriptor entry : classpath.getEntryDescriptors()) {
if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE && entry.getPath().toString().endsWith(path)) {
return entry;
}
}
return null;
}
}