This repository has been archived by the owner on Nov 10, 2017. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure that source and test folders are at the top of the classpath l…
…ist. After running the other Classpath Configuration classes the source folders are out of sequence, causing all sorts of problems looking up source. This is an attempt to re-order the classpaths. The order of the entries are: src/main/java src/main/resources src/test/java src/test/resources All other entries are kept the same in the classpath. The reordering has to be the last entry to run in the RawClasspathConfigurations. Update reordering config to user rawclasspath Correctly reorder the source folders after updating classpaths.
- Loading branch information
1 parent
696f194
commit 8ed6684
Showing
3 changed files
with
125 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
...a/me/gladwell/eclipse/m2e/android/configuration/classpath/ReorderClasspathConfigurer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package me.gladwell.eclipse.m2e.android.configuration.classpath; | ||
|
||
import java.util.ArrayList; | ||
import java.util.LinkedHashSet; | ||
|
||
import org.eclipse.core.runtime.NullProgressMonitor; | ||
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.m2e.jdt.IClasspathDescriptor; | ||
|
||
import me.gladwell.eclipse.m2e.android.Log; | ||
import me.gladwell.eclipse.m2e.android.project.EclipseAndroidProject; | ||
import me.gladwell.eclipse.m2e.android.project.MavenAndroidProject; | ||
|
||
public class ReorderClasspathConfigurer implements RawClasspathConfigurer { | ||
|
||
private static final String SRC_TEST_RESOURCES = "src/test/resources"; | ||
private static final String SRC_TEST_JAVA = "src/test/java"; | ||
private static final String SRC_MAIN_RESOURCES = "src/main/resources"; | ||
private static final String SRC_MAIN_JAVA = "src/main/java"; | ||
protected IClasspathEntry[] originalClasspathEntries; | ||
protected ArrayList<IClasspathEntry> arrayEntries; | ||
|
||
public boolean shouldApplyTo(MavenAndroidProject project) { | ||
return true; | ||
} | ||
|
||
protected void addMavenSourceFolder() { | ||
IClasspathEntry newEntry = findMavenStandardSourceFolder(); | ||
addEntry(newEntry); | ||
} | ||
|
||
protected void addMavenResourceFolder() { | ||
IClasspathEntry newEntry = findMavenStandardResourceFolder(); | ||
addEntry(newEntry); | ||
} | ||
|
||
protected void addMavenTestSourceFolder() { | ||
IClasspathEntry newEntry = findMavenStandardTestSourceFolder(); | ||
addEntry(newEntry); | ||
} | ||
|
||
protected void addMavenTestResourceFolder() { | ||
IClasspathEntry newEntry = findMavenStandardTestResourceFolder(); | ||
addEntry(newEntry); | ||
} | ||
|
||
protected void addTheRest() { | ||
for (IClasspathEntry classpathEntry : originalClasspathEntries) { | ||
if (!classpathEntry.getPath().toString().contains(SRC_TEST_JAVA) | ||
&& !classpathEntry.getPath().toString().contains(SRC_TEST_RESOURCES) | ||
&& !classpathEntry.getPath().toString().contains(SRC_MAIN_RESOURCES) | ||
&& !classpathEntry.getPath().toString().contains(SRC_MAIN_JAVA)) { | ||
addEntry(classpathEntry); | ||
} | ||
} | ||
} | ||
|
||
protected void addEntry(IClasspathEntry entry) { | ||
if (entry != null) { | ||
arrayEntries.add(entry); | ||
} | ||
} | ||
|
||
private IClasspathEntry findMavenStandardSourceFolder() { | ||
return findClasspathEntry(SRC_MAIN_JAVA); | ||
} | ||
|
||
private IClasspathEntry findMavenStandardResourceFolder() { | ||
return findClasspathEntry(SRC_MAIN_RESOURCES); | ||
} | ||
|
||
private IClasspathEntry findMavenStandardTestSourceFolder() { | ||
return findClasspathEntry(SRC_TEST_JAVA); | ||
} | ||
|
||
private IClasspathEntry findMavenStandardTestResourceFolder() { | ||
return findClasspathEntry(SRC_TEST_RESOURCES); | ||
} | ||
|
||
private IClasspathEntry findClasspathEntry(String substring) { | ||
for (IClasspathEntry classpathEntry : originalClasspathEntries) { | ||
String path = classpathEntry.getPath().toString(); | ||
if (path.contains(substring)) { | ||
return classpathEntry; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
public void configure(MavenAndroidProject mavenProject, EclipseAndroidProject eclipseProject, | ||
IClasspathDescriptor classpath) { | ||
arrayEntries = new ArrayList<IClasspathEntry>(); | ||
|
||
IJavaProject javaproject = JavaCore.create(eclipseProject.getProject()); | ||
|
||
originalClasspathEntries = javaproject.readRawClasspath(); | ||
|
||
addMavenSourceFolder(); | ||
addMavenResourceFolder(); | ||
addMavenTestSourceFolder(); | ||
addMavenTestResourceFolder(); | ||
addTheRest(); | ||
|
||
|
||
IClasspathEntry[] newEntries = new IClasspathEntry[arrayEntries.size()]; | ||
arrayEntries.toArray(newEntries); | ||
|
||
try { | ||
javaproject.setRawClasspath(newEntries, new NullProgressMonitor()); | ||
javaproject.save(new NullProgressMonitor(), false); | ||
} catch (Exception ex) { | ||
Log.warn(ex.getMessage()); | ||
} | ||
|
||
} | ||
|
||
} |