Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix disappearing classpath entries on project update #12

Closed
wants to merge 2 commits into from
Closed
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
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry exported="true" kind="lib" path="lib/local-jar-classpath.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src/main/java/"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
@@ -0,0 +1,6 @@
/target
/workspaceState.ser
/bin
!.project
!.classpath
!.settings/
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>local-jar-classpath</name>
<comment></comment>
<projects>
</projects>
</projectDescription>
@@ -0,0 +1,8 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: local-jar-classpath
Bundle-SymbolicName: local-jar-classpath;singleton:=true
Bundle-Version: 0.0.1.qualifier
Bundle-Vendor: fred
Bundle-ClassPath: .,
lib/local-jar-classpath.jar
@@ -0,0 +1,6 @@
source.. = src/main/java/
output.. = target/classes/
bin.includes = plugin.xml,\
META-INF/,\
.,\
lib/local-jar-classpath.jar
Binary file not shown.
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
</plugin>
22 changes: 22 additions & 0 deletions org.sonatype.tycho.m2e.tests/projects/local-jar-classpath/pom.xml
@@ -0,0 +1,22 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>foo.bar</groupId>
<artifactId>local-jar-classpath</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
<properties>
<tycho-version>0.12.0</tycho-version>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-maven-plugin</artifactId>
<version>${tycho-version}</version>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,6 @@
package pde;

import foo.bar.SomeClass;

public class Activator extends SomeClass {
}
Expand Up @@ -12,7 +12,9 @@

import org.eclipse.core.resources.IProject;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.m2e.core.MavenPlugin;
import org.eclipse.m2e.core.project.IMavenProjectFacade;
import org.eclipse.m2e.core.project.configurator.ILifecycleMapping;
import org.eclipse.m2e.tests.common.AbstractLifecycleMappingTest;
Expand Down Expand Up @@ -113,4 +115,35 @@ public void testTychoLifecycleMapping_EclipseUpdateSite()
IProject project = facade.getProject();
assertTrue( project.hasNature( PDE.SITE_NATURE ) );
}


public void testUpdateWhenJarInClasspath_EclipsePlugin()
throws Exception
{
IMavenProjectFacade facade =
importProjectAndAssertLifecycleMappingType( "projects/local-jar-classpath", "pom.xml" );

IProject project = facade.getProject();
assertTrue( project.hasNature( PDE.PLUGIN_NATURE ) );
assertTrue( project.hasNature( JavaCore.NATURE_ID ) );
IPluginModelBase model = PluginRegistry.findModel( project );
assertNotNull( model );

IJavaProject jproject = JavaCore.create(project);
assertNotNull(jproject);
IClasspathEntry[] classpathEntries = jproject.getRawClasspath();
assertEquals( 4, classpathEntries.length );
MavenPlugin.getProjectConfigurationManager().updateProjectConfiguration(project, monitor);
jproject = null;
waitForJobsToComplete();

jproject = JavaCore.create(project);
classpathEntries = jproject.getRawClasspath();
assertEquals( 4, classpathEntries.length );
assertClasspathContains( classpathEntries, "org.eclipse.jdt.launching.JRE_CONTAINER" );
assertClasspathContains( classpathEntries, "org.eclipse.pde.core.requiredPlugins" );
assertClasspathContains( classpathEntries, "/local-jar-classpath/src/main/java/" );
assertClasspathContains( classpathEntries, "/local-jar-classpath/lib/local-jar-classpath.jar" );

}
}
Expand Up @@ -131,7 +131,6 @@ public void configurePDEBundleProject( IProject project, MavenProject mavenProje

// PDE can't handle default JDT classpath
IJavaProject javaProject = JavaCore.create( project );
javaProject.setRawClasspath( new IClasspathEntry[0], true, monitor );
javaProject.setOutputLocation( getOutputLocation( project, mavenProject, monitor ), monitor );

// see org.eclipse.pde.internal.ui.wizards.tools.UpdateClasspathJob
Expand Down Expand Up @@ -236,10 +235,10 @@ public static IFile getBundleManifest( IProject project )
private static void setClasspath( IProject project, IPluginModelBase model, IProgressMonitor monitor )
throws CoreException
{
ClasspathComputer.setClasspath( project, model );

IClasspathEntry[] entries = ClasspathComputer.getClasspath(project, model, null, true /*clear existing entries*/, true);
JavaCore.create(project).setRawClasspath(entries, null);
// workaround PDE sloppy model management during the first multimodule project import in eclipse session
// 1. m2e creates all modules as simple workspace projects without JDT or PDE nattues
// 1. m2e creates all modules as simple workspace projects without JDT or PDE natures
// 2. first call to org.eclipse.pde.internal.core.PluginModelManager.initializeTable() reads all workspace
// projects regardless of their natures (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=319268)
// 3. going through all projects one by one
Expand All @@ -248,7 +247,7 @@ private static void setClasspath( IProject project, IPluginModelBase model, IPro
// that do not have JAVA nature. at this point PDE classpath is missing some/all workspace dependencies.
// 4. PDE does not re-resolve classpath when dependencies get JAVA nature enabled

// as a workaround, touch project bundle manifests to force PDE re-read the model, reresolve dependencies
// as a workaround, touch project bundle manifests to force PDE re-read the model, re-resolve dependencies
// and recalculate PDE classpath

IFile manifest = PDEProjectHelper.getBundleManifest( project );
Expand Down
17 changes: 3 additions & 14 deletions pom.xml
Expand Up @@ -26,8 +26,10 @@
<packaging>pom</packaging>

<properties>
<tychoVersion>0.18.1</tychoVersion>
<repositoryPathId>m2eclipse-tycho</repositoryPathId>
<p2MetadataName>Tycho Project Configurators Update Site</p2MetadataName>
<tycho.test.jvmArgs>-Xmx800m -XX:MaxPermSize=256m</tycho.test.jvmArgs>
</properties>

<modules>
Expand All @@ -40,7 +42,7 @@
<repositories>
<repository>
<id>m2e-tests</id>
<url>http://repository.tesla.io:8081/nexus/content/sites/m2e.extras/m2e/1.4.0/N/LATEST/</url>
<url>http://repository.tesla.io:8081/nexus/content/sites/m2e.extras/m2e/1.5.0/N/LATEST/</url>
<layout>p2</layout>
</repository>
</repositories>
Expand Down Expand Up @@ -90,19 +92,6 @@
</build>

<profiles>
<profile>
<id>sun-jvm</id>
<activation>
<property>
<name>java.vendor.url</name>
<value>http://java.sun.com/</value>
</property>
</activation>
<properties>
<tycho.test.jvmArgs>-Xmx800m -XX:MaxPermSize=256m</tycho.test.jvmArgs>
</properties>
</profile>

<profile>
<id>osx</id>
<activation>
Expand Down