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;
importstatic java.util.Arrays.asList;
importstatic org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME;
importstatic org.eclipse.jdt.launching.JavaRuntime.newArchiveRuntimeClasspathEntry;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import me.gladwell.eclipse.m2e.android.project.AndroidProjectFactory;
import me.gladwell.eclipse.m2e.android.project.EclipseAndroidProject;
import me.gladwell.eclipse.m2e.android.project.MavenAndroidProject;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Path;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
import org.eclipse.jdt.launching.IRuntimeClasspathProvider;
import com.google.inject.Inject;
publicclass JUnitClasspathProvider implements IRuntimeClasspathProvider {
privatefinal IRuntimeClasspathProvider classpathProvider;
privatefinal IWorkspace workspace;
privatefinal AndroidProjectFactory<EclipseAndroidProject, IProject> factory;
privatefinal AndroidProjectFactory<MavenAndroidProject, EclipseAndroidProject> factory2;
@Inject
public JUnitClasspathProvider(@Maven IRuntimeClasspathProvider classpathProvider, IWorkspace workspace,
AndroidProjectFactory<EclipseAndroidProject, IProject> factory,
AndroidProjectFactory<MavenAndroidProject, EclipseAndroidProject> factory2) {
super();
this.classpathProvider = classpathProvider;
this.workspace = workspace;
this.factory = factory;
this.factory2 = factory2;
}
public IRuntimeClasspathEntry[] computeUnresolvedClasspath(ILaunchConfiguration config) throws CoreException {
List<IRuntimeClasspathEntry> classpath = new ArrayList<IRuntimeClasspathEntry>(
asList(classpathProvider.computeUnresolvedClasspath(config)));
addPlatformDependencies(config, classpath);
addBinaryFolder(config, classpath);
return classpath.toArray(new IRuntimeClasspathEntry[classpath.size()]);
}
privatevoid addPlatformDependencies(ILaunchConfiguration config, List<IRuntimeClasspathEntry> classpath)
throws CoreException {
IProject project = workspace.getRoot().getProject(config.getAttribute(ATTR_PROJECT_NAME, (String) null));
MavenAndroidProject androidProject = factory2.createAndroidProject(factory.createAndroidProject(project));
for (String dependency : androidProject.getPlatformProvidedDependencies()) {
classpath.add(newArchiveRuntimeClasspathEntry(new Path(dependency)));
}
}
privatevoid addBinaryFolder(ILaunchConfiguration config, List<IRuntimeClasspathEntry> classpath)
throws CoreException {
IProject project = workspace.getRoot().getProject(config.getAttribute(ATTR_PROJECT_NAME, (String) null));
IFolder binaries = project.getFolder("bin" + File.separator + "classes");
classpath.add(newArchiveRuntimeClasspathEntry(binaries.getLocation()));
}
public IRuntimeClasspathEntry[] resolveClasspath(IRuntimeClasspathEntry[] classpath, ILaunchConfiguration config)
throws CoreException {
return classpathProvider.resolveClasspath(classpath, config);
}
}