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

Fix Android container not exported in m2e 1.6 #363

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -71,7 +71,7 @@ public void configure(ProjectConfigurationRequest request, IProgressMonitor moni
.getProject());

if (mavenProject.isAndroidProject()) {
if (shouldCallJavaProjectConfigurator()) {
if (!usesM2E1_6OrNewer()) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improved descriptive method name, but I think its better to have a method that returns whether we're using M2E 1.5 or earlier instead to avoid the use of the negation ! operators which can be confusing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 good point, didn't spot that

javaProjectConfigurator.configure(request, monitor);
}

Expand Down Expand Up @@ -126,10 +126,10 @@ public void configureRawClasspath(ProjectConfigurationRequest request, IClasspat
}
}

private static boolean shouldCallJavaProjectConfigurator() {
public static boolean usesM2E1_6OrNewer() {
Bundle bundle = Platform.getBundle("org.eclipse.m2e.core");

return bundle.getVersion().compareTo(M2E_VERSION_NEW_CONFIGURATOR_ORDER) < 0;
return bundle.getVersion().compareTo(M2E_VERSION_NEW_CONFIGURATOR_ORDER) >= 0;
}

}
Expand Up @@ -11,6 +11,8 @@
import com.google.inject.AbstractModule;
import com.google.inject.Provides;

import me.gladwell.eclipse.m2e.android.AndroidMavenProjectConfigurator;

public class ClasspathModule extends AbstractModule {

@Override
Expand Down Expand Up @@ -44,7 +46,9 @@ List<ClasspathConfigurer> provideClasspathConfigurers(final AddNonRuntimeClasspa
classpathConfigurers.add(new ModifySourceFolderOutputClasspathConfigurer());
classpathConfigurers.add(new RemoveJREClasspathContainerConfigurer());
classpathConfigurers.add(new MarkMavenClasspathContianerExportedConfigurer());
classpathConfigurers.add(new MarkAndroidClasspathContainerNotExportedConfigurer());
if (!AndroidMavenProjectConfigurator.usesM2E1_6OrNewer()) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Nice way of maintaining backwards compatibility.

classpathConfigurers.add(new MarkAndroidClasspathContainerNotExportedConfigurer());
}
classpathConfigurers.add(new IgnoreOptionalWarningsConfigurer());

return Collections.unmodifiableList(classpathConfigurers);
Expand Down
@@ -0,0 +1,67 @@
/*******************************************************************************
* Copyright (c) 2013, 2014, 2015 Ricardo Gladwell
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to update the copyright notices.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not really matter, and actually i just copied this class.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're sure you should make sure you get credit.

* 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.configuration.workspace;

import java.util.List;

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 org.eclipse.m2e.jdt.IClasspathEntryDescriptor;
import org.eclipse.m2e.jdt.internal.ClasspathDescriptor;

import com.google.inject.Inject;

import me.gladwell.eclipse.m2e.android.configuration.ProjectConfigurationException;
import me.gladwell.eclipse.m2e.android.project.IDEAndroidProject;
import me.gladwell.eclipse.m2e.android.project.IDEAndroidProjectFactory;
import me.gladwell.eclipse.m2e.android.project.MavenAndroidProject;

public class MarkAndroidClasspathContainerNotExportedConfigurer implements WorkspaceConfigurer {

private final IDEAndroidProjectFactory factory;

@Inject
public MarkAndroidClasspathContainerNotExportedConfigurer(IDEAndroidProjectFactory factory) {
this.factory = factory;
}

public boolean isConfigured(IDEAndroidProject project) {
return false;
}

public boolean isValid(MavenAndroidProject project) {
return true;
}

public void configure(IDEAndroidProject eclipseProject, MavenAndroidProject mavenProject) {
try {
IJavaProject javaProject = JavaCore.create(eclipseProject.getProject());
IClasspathDescriptor classpath = new ClasspathDescriptor(javaProject);
IDEAndroidProject androidProject = factory.createAndroidProject(javaProject.getProject(), classpath);

androidProject.getClasspath().getAndroidClasspathContainer().markNotExported();

List<IClasspathEntryDescriptor> descriptors = classpath.getEntryDescriptors();
IClasspathEntry[] entries = new IClasspathEntry[descriptors.size()];

for (int i = 0; i < descriptors.size(); ++i) {
entries[i] = descriptors.get(i).toClasspathEntry();
}

javaProject.setRawClasspath(entries, new NullProgressMonitor());
} catch (JavaModelException e) {
throw new ProjectConfigurationException("Could not mark ADT libraries container as not exported", e);
}
}

}
Expand Up @@ -7,23 +7,30 @@
import com.google.inject.AbstractModule;
import com.google.inject.Provides;

import me.gladwell.eclipse.m2e.android.AndroidMavenProjectConfigurator;

public class WorkspaceModule extends AbstractModule {

@Override
protected void configure() {
bind(LibraryDependenciesWorkspaceConfigurer.class);
bind(MarkAndroidClasspathContainerNotExportedConfigurer.class);
}

@Provides
List<WorkspaceConfigurer> provideWorkspaceConfigurers(LibraryDependenciesWorkspaceConfigurer configurer) {
List<WorkspaceConfigurer> provideWorkspaceConfigurers(LibraryDependenciesWorkspaceConfigurer libraryDependenciesConfigurer,
MarkAndroidClasspathContainerNotExportedConfigurer markAndroidClasspathContainerNotExportedConfigurer) {
final List<WorkspaceConfigurer> workspaceConfigurers = new ArrayList<WorkspaceConfigurer>();

workspaceConfigurers.add(new FixerWorkspaceConfigurer());
if (AndroidMavenProjectConfigurator.usesM2E1_6OrNewer()) {
workspaceConfigurers.add(markAndroidClasspathContainerNotExportedConfigurer);
}
workspaceConfigurers.add(new AddAndroidNatureWorkspaceConfigurer());
workspaceConfigurers.add(new OrderBuildersWorkspaceConfigurer());
workspaceConfigurers.add(new ConvertLibraryWorkspaceConfigurer());
workspaceConfigurers.add(new ConvertLibraryWorkspaceConfigurer());
workspaceConfigurers.add(configurer);
workspaceConfigurers.add(libraryDependenciesConfigurer);
workspaceConfigurers.add(new LinkAssetsFolderConfigurer());
workspaceConfigurers.add(new LinkAndroidManifestConfigurer());
workspaceConfigurers.add(new LinkResourceDirectoryConfigurer());
Expand Down