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

Commit

Permalink
better support for binary projects for shaded libraries like wagon-ht…
Browse files Browse the repository at this point in the history
…tp-2.10-shaded.jar

Signed-off-by: Igor Fedorenko <igor@ifedorenko.com>
  • Loading branch information
ifedorenko committed Aug 30, 2016
1 parent 8c6fad4 commit b4f88cc
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 6 deletions.
@@ -0,0 +1,75 @@
/*******************************************************************************
* Copyright (c) 2011-2016 Igor Fedorenko
* 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
*
* Contributors:
* Igor Fedorenko - initial API and implementation
*******************************************************************************/
package com.ifedorenko.m2e.binaryproject.sourcelookup;

import static com.ifedorenko.m2e.binaryproject.sourcelookup.BinaryProjectDescriber.getBinaryLocation;
import static com.ifedorenko.m2e.sourcelookup.internal.jdt.AbstractProjectSourceDescriber.getClasspath;

import java.io.File;
import java.util.Map;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.debug.core.sourcelookup.ISourceContainer;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.launching.sourcelookup.containers.PackageFragmentRootSourceContainer;
import org.eclipse.m2e.core.MavenPlugin;
import org.eclipse.m2e.core.embedder.ArtifactKey;
import org.eclipse.m2e.core.project.IMavenProjectFacade;
import org.eclipse.m2e.core.project.IMavenProjectRegistry;

import com.ifedorenko.m2e.sourcelookup.internal.jdt.ISourceContainerResolver;
import com.ifedorenko.m2e.sourcelookup.internal.launch.MavenSourceContainerResolver;

// useful to lookup shaded binary projects like wagon-http-2.10-shaded.jar
public class BinaryProjectContainerResolver extends MavenSourceContainerResolver implements ISourceContainerResolver {

@Override
protected ISourceContainer resovleSourceContainer(ArtifactKey artifact, IProgressMonitor monitor) {
String groupId = artifact.getGroupId();
String artifactId = artifact.getArtifactId();
String version = artifact.getVersion();

IMavenProjectRegistry projectRegistry = MavenPlugin.getMavenProjectRegistry();

IMavenProjectFacade mavenProject = projectRegistry.getMavenProject(groupId, artifactId, version);
if (mavenProject == null) {
return null;
}

IProject project = mavenProject.getProject();

try {
final File binaryLocation = getBinaryLocation(project);
if (binaryLocation == null) {
return null;
}

IJavaProject javaProject = JavaCore.create(project);

Map<File, IPackageFragmentRoot> classpath = getClasspath(javaProject);
IPackageFragmentRoot binary = classpath.remove(binaryLocation);

if (binary == null) {
return null; // this is a bug somewhere in my code
}

return new PackageFragmentRootSourceContainer(binary);
} catch (CoreException e) {
// ignore, maybe log
}

return null;
}
}
Expand Up @@ -13,6 +13,7 @@
import java.io.File;
import java.util.Map;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IPackageFragmentRoot;
Expand All @@ -23,8 +24,8 @@

public class BinaryProjectDescriber extends AbstractProjectSourceDescriber {

private static File getBinaryLocation(IJavaProject project) throws CoreException {
final String binaryLocation = project.getProject().getPersistentProperty(BinaryProjectPlugin.QNAME_JAR);
static File getBinaryLocation(IProject project) throws CoreException {
final String binaryLocation = project.getPersistentProperty(BinaryProjectPlugin.QNAME_JAR);
if (binaryLocation == null) {
return null;
}
Expand All @@ -33,7 +34,7 @@ private static File getBinaryLocation(IJavaProject project) throws CoreException

@Override
public void describeProject(IJavaProject project, IJavaProjectSourceDescription description) throws CoreException {
final File binaryLocation = getBinaryLocation(project);
final File binaryLocation = getBinaryLocation(project.getProject());
if (binaryLocation == null) {
return;
}
Expand Down
Expand Up @@ -73,7 +73,7 @@ protected static boolean isSourceProject(IJavaProject project) throws JavaModelE
return false;
}

protected static Map<File, IPackageFragmentRoot> getClasspath(IJavaProject project) throws JavaModelException {
public static Map<File, IPackageFragmentRoot> getClasspath(IJavaProject project) throws JavaModelException {
final Map<File, IPackageFragmentRoot> classpath = new LinkedHashMap<>();
for (IPackageFragmentRoot fragment : project.getPackageFragmentRoots()) {
if (fragment.getKind() == IPackageFragmentRoot.K_BINARY) {
Expand Down
Expand Up @@ -146,7 +146,7 @@ protected Collection<ArtifactKey> identifyCentralSearch(File file) {
return null;
}

protected Collection<ArtifactKey> scanPomProperties(File classesLocation) {
public Collection<ArtifactKey> scanPomProperties(File classesLocation) {
Set<ArtifactKey> artifacts = new LinkedHashSet<>();
for (Properties pomProperties : scanner.scan(classesLocation, "pom.properties")) {
String groupId = pomProperties.getProperty("groupId");
Expand Down
Expand Up @@ -53,7 +53,7 @@ public Collection<ISourceContainer> resolveSourceContainers(File classesLocation
return result;
}

private ISourceContainer resovleSourceContainer(ArtifactKey artifact, IProgressMonitor monitor) {
protected ISourceContainer resovleSourceContainer(ArtifactKey artifact, IProgressMonitor monitor) {

This comment has been minimized.

Copy link
@apupier

apupier Aug 30, 2016

typo resovleSourceContainer --> resolveSourceContainer
Still time to fix it before releasing a new version

String groupId = artifact.getGroupId();
String artifactId = artifact.getArtifactId();
String version = artifact.getVersion();
Expand Down

0 comments on commit b4f88cc

Please sign in to comment.