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

Commit

Permalink
Modifying classpath honors previous attributes
Browse files Browse the repository at this point in the history
When the output location of a sourcepath entry was modified by
m2e-android, it created a whole new classpath entry with default
values, so properties added to the old entry by m2e was dropped. This
new implementation just modifies the old entry object, so all
attributes added by m2e are retained. Also when the Maven Container
was set as exported, the attributes of the old entry was not copied
into the new entry. Now all attributes are copied to the new entry.

https://github.com/rgladwell/m2e-android/issues/182
  • Loading branch information
WonderCsabo committed Jan 16, 2015
1 parent 29b2c31 commit 09f56d6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,21 @@
import java.io.File;

import org.eclipse.core.resources.IProject;
import org.eclipse.m2e.jdt.IClasspathDescriptor;
import org.eclipse.m2e.jdt.IClasspathEntryDescriptor;

public class EclipseSourceEntry implements SourceEntry {

private final IProject project;
private final IClasspathDescriptor classpath;
private final IClasspathEntryDescriptor entry;

public EclipseSourceEntry(IProject project, IClasspathDescriptor classpath, IClasspathEntryDescriptor entry) {
public EclipseSourceEntry(IProject project, IClasspathEntryDescriptor entry) {
super();
this.project = project;
this.classpath = classpath;
this.entry = entry;
}

public void setOutputLocation(String path) {
classpath.removeEntry(entry.getPath());
classpath.addSourceEntry(entry.getPath(), project.getFullPath().append(path), true);
entry.setOutputLocation(project.getFullPath().append(path));
}

public String getOutputLocation() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ 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));
entries.add(new EclipseSourceEntry(project.getProject(), entry));
}
}
return entries;
Expand Down Expand Up @@ -84,16 +84,18 @@ public void addSourceEntry(String path) {
}

public void markExported(String path) {
IClasspathEntry oldEntry = findContainerMatching(classpath, path);
IClasspathEntry newEntry = newContainerEntry(oldEntry.getPath(), true);
classpath.removeEntry(oldEntry.getPath());
classpath.addEntry(newEntry);
setClassPathEntryExported(path, true);
}

public void markNotExported(String path) {
setClassPathEntryExported(path, false);
}

private void setClassPathEntryExported(String path, boolean exported) {
IClasspathEntry oldEntry = findContainerMatching(classpath, path);
if(oldEntry != null) {
IClasspathEntry newEntry = newContainerEntry(oldEntry.getPath(), false);
if (oldEntry != null) {
IClasspathEntry newEntry = newContainerEntry(oldEntry.getPath(), oldEntry.getAccessRules(),
oldEntry.getExtraAttributes(), exported);
classpath.removeEntry(oldEntry.getPath());
classpath.addEntry(newEntry);
} else {
Expand All @@ -102,7 +104,7 @@ public void markNotExported(String path) {
}

public SourceEntry getSourceEntry(String path) {
return new EclipseSourceEntry(project.getProject(), classpath, findSourceEntryDescriptor(classpath, path));
return new EclipseSourceEntry(project.getProject(), findSourceEntryDescriptor(classpath, path));
}

}

0 comments on commit 09f56d6

Please sign in to comment.