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) 2014 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.project;
importstatic me.gladwell.eclipse.m2e.android.configuration.Classpaths.findSourceEntryDescriptor;
importstatic me.gladwell.eclipse.m2e.android.configuration.Classpaths.findContainerContaining;
importstatic me.gladwell.eclipse.m2e.android.configuration.Classpaths.findContainerMatching;
importstatic org.eclipse.jdt.core.JavaCore.newContainerEntry;
importstatic org.eclipse.jdt.core.JavaCore.setClasspathContainer;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import me.gladwell.eclipse.m2e.android.configuration.ProjectConfigurationException;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.core.IClasspathContainer;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.m2e.jdt.IClasspathDescriptor;
import org.eclipse.m2e.jdt.IClasspathEntryDescriptor;
publicclass MavenEclipseClasspath implements Classpath {
privatefinal IJavaProject project;
privatefinal IClasspathDescriptor classpath;
public MavenEclipseClasspath(IJavaProject project, IClasspathDescriptor classpath) {
super();
this.project = project;
this.classpath = classpath;
}
public Iterable<SourceEntry> getSourceEntries() {
List<SourceEntry> entries = new ArrayList<SourceEntry>();
for(IClasspathEntryDescriptor entry : classpath.getEntryDescriptors()) {
if(entry.getOutputLocation() != null && entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
entries.add(new EclipseSourceEntry(project.getProject(), classpath, entry));
}
}
return entries;
}
publicvoid addContainer(IClasspathContainer container) {
try {
setClasspathContainer(container.getPath(),
new IJavaProject[] { project }, new IClasspathContainer[] { container },
new NullProgressMonitor());
classpath.addEntry(newContainerEntry(container.getPath(), false));
} catch (JavaModelException e) {
thrownew ProjectConfigurationException(e);
}
}
publicvoid removeContainer(String containerId) {
IClasspathEntry entry = findContainerContaining(classpath, containerId);
classpath.removeEntry(entry.getPath());
}
publicvoid addSourceEntry(String path) {
IFolder folder = project.getProject().getFolder(path + File.separator);
if (!folder.exists()) {
try {
folder.create(true, true, new NullProgressMonitor());
} catch (CoreException e) {
thrownew ProjectConfigurationException(e);
}
}
if (!classpath.containsPath(new Path(path))) {
classpath.addSourceEntry(folder.getFullPath(), null, false);
}
}
publicvoid markExported(String path) {
IClasspathEntry oldEntry = findContainerMatching(classpath, path);
IClasspathEntry newEntry = newContainerEntry(oldEntry.getPath(), true);
classpath.removeEntry(oldEntry.getPath());
classpath.addEntry(newEntry);
}
publicvoid markNotExported(String path) {
IClasspathEntry oldEntry = findContainerMatching(classpath, path);
if(oldEntry != null) {
IClasspathEntry newEntry = newContainerEntry(oldEntry.getPath(), false);
classpath.removeEntry(oldEntry.getPath());
classpath.addEntry(newEntry);
} else {
// TODO log warning here
}
}
public SourceEntry getSourceEntry(String path) {
returnnew EclipseSourceEntry(project.getProject(), classpath, findSourceEntryDescriptor(classpath, path));
}
}