blob: 627ac21997256389754d754956f8546b6fb6bbea [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2014 Bosch Software Innovations GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html
* The Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
* Bosch Software Innovations GmbH - Please refer to git log
*
*******************************************************************************/
package org.eclipse.vorto.codegen.api.tasks.eclipse;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.launching.IVMInstall;
import org.eclipse.jdt.launching.JavaRuntime;
/**
* Configures the classpath and source folders for a Java Project
*
*
*
*/
public class ClasspathConfiguration extends AbstractConfiguration {
private String[] sourceFolders = new String[0];
public ClasspathConfiguration(String... sourceFolders) {
this.sourceFolders = sourceFolders;
}
@Override
public IEclipseProjectConfiguration configure(IProject project) {
IJavaProject javaProject = JavaCore.create(project);
try {
javaProject.setRawClasspath(getClasspathEntries(project),
new NullProgressMonitor());
javaProject.setOutputLocation(project.getFolder("target")
.getFullPath(), new NullProgressMonitor());
} catch (JavaModelException e1) {
}
return this;
}
private IClasspathEntry[] getClasspathEntries(IProject project) {
IClasspathEntry[] newEntries = new IClasspathEntry[sourceFolders.length + 1];
for (int i = 0; i < sourceFolders.length; i++) {
newEntries[i] = JavaCore.newSourceEntry(project.getFolder(
sourceFolders[i]).getFullPath());
}
newEntries[sourceFolders.length] = getVmClasspathEntry();
return newEntries;
}
private IClasspathEntry getVmClasspathEntry() {
IPath containerPath = new Path(JavaRuntime.JRE_CONTAINER);
IVMInstall vmInstall = JavaRuntime.getDefaultVMInstall();
IPath vmPath = containerPath.append(
vmInstall.getVMInstallType().getId()).append(
vmInstall.getName());
return JavaCore.newContainerEntry(vmPath);
}
}