Skip to content
This repository has been archived by the owner on Nov 17, 2020. It is now read-only.

Commit

Permalink
Merge pull request #34 from huitseeker/issue/classpathJobs
Browse files Browse the repository at this point in the history
Eclipse job compliance
  • Loading branch information
davidB committed Sep 24, 2014
2 parents cc32ef1 + a3cf2a3 commit 943bed6
Showing 1 changed file with 50 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jdt.core.ClasspathContainerInitializer;
import org.eclipse.jdt.core.IClasspathAttribute;
import org.eclipse.jdt.core.IClasspathContainer;
Expand All @@ -33,7 +36,6 @@
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.internal.core.ClasspathAttribute;
import org.eclipse.jdt.internal.core.ClasspathEntry;
import org.eclipse.m2e.core.project.IMavenProjectFacade;
import org.eclipse.m2e.core.project.configurator.ProjectConfigurationRequest;
import org.eclipse.m2e.jdt.AbstractJavaProjectConfigurator;
Expand Down Expand Up @@ -167,20 +169,27 @@ protected IPath getFullPath( IMavenProjectFacade facade, File file ) {
return super.getFullPath(facade, file);
}

private void removeScalaFromMavenContainer(IClasspathDescriptor classpath) {
classpath.removeEntry(new IClasspathDescriptor.EntryFilter() {
public boolean accept(IClasspathEntryDescriptor descriptor) {
boolean back = "org.scala-lang".equals(descriptor.getGroupId());
//TODO, use content of Scala Library Container instead of hardcoded value
back = back && (
"scala-library".equals(descriptor.getArtifactId())
private void removeScalaFromMavenContainer(final IClasspathDescriptor classpath) {
Job classpathRemoval = new Job("removeScalaLibFromClassPath") {
@Override
protected IStatus run(IProgressMonitor monitor) {
classpath.removeEntry(new IClasspathDescriptor.EntryFilter() {
public boolean accept(IClasspathEntryDescriptor descriptor) {
boolean back = "org.scala-lang".equals(descriptor.getGroupId());
//TODO, use content of Scala Library Container instead of hardcoded value
back = back && ("scala-library".equals(descriptor.getArtifactId())
//|| "scala-compiler".equals(descriptor.getArtifactId())
|| "scala-dbc".equals(descriptor.getArtifactId())
|| "scala-swing".equals(descriptor.getArtifactId())
);
return back;
|| "scala-dbc".equals(descriptor.getArtifactId()) || "scala-swing".equals(descriptor.getArtifactId()));
return back;
}
});

return Status.OK_STATUS;
}
});
};

classpathRemoval.setPriority(Job.BUILD);
classpathRemoval.schedule();
}

/**
Expand All @@ -189,15 +198,35 @@ public boolean accept(IClasspathEntryDescriptor descriptor) {
* Should already be done when adding nature
* @see scala.tools.eclipse.Nature#configure()
*/
private void sortContainerScalaJre(IProject project, IProgressMonitor monitor) throws CoreException {
IJavaProject javaProject = JavaCore.create(project);
IClasspathEntry[] classpathEntries = javaProject.getRawClasspath();
private void sortContainerScalaJre(final IProject project, IProgressMonitor monitor) throws CoreException {
Job classpathOrdering = new Job("orderScalaArtefactsonClaspath"){
@Override
protected IStatus run(IProgressMonitor monitor) {
IJavaProject javaProject = JavaCore.create(project);
try {
IClasspathEntry[] classpathEntries = javaProject.getRawClasspath();

Boolean sorted = true;
for (int i = 0; i < classpathEntries.length - 1; i++) {
if (comparator.compare(classpathEntries[i], classpathEntries[i+1]) > 0){sorted = false; break;}
}

List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>(classpathEntries.length);
Collections.addAll(entries, classpathEntries);
if(!sorted) {
List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>(classpathEntries.length);
Collections.addAll(entries, classpathEntries);

Collections.sort(entries, comparator);
javaProject.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), monitor);
}
return Status.OK_STATUS;
} catch(JavaModelException e) {
return Status.CANCEL_STATUS;
}
}
};

Collections.sort(entries, comparator);
javaProject.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), monitor);
classpathOrdering.setPriority(Job.BUILD);
classpathOrdering.schedule();
}

private boolean isScalaProject(IProject project) {
Expand Down Expand Up @@ -276,6 +305,7 @@ private static void addDeployableAttribute(IJavaProject javaProject, IClasspathA
throws JavaModelException, CoreException {
if (javaProject == null) return;
ClasspathContainerInitializer scalaInitializer = JavaCore.getClasspathContainerInitializer(SCALA_CONTAINER_PATH);
if (scalaInitializer == null) return;
IPath scalaContainerPath = Path.fromPortableString(SCALA_CONTAINER_PATH);
Boolean updateAble = scalaInitializer.canUpdateClasspathContainer(scalaContainerPath, javaProject);
final IClasspathContainer scalaLibrary = JavaCore.getClasspathContainer(scalaContainerPath, javaProject);
Expand Down

0 comments on commit 943bed6

Please sign in to comment.