This repository has been archived by the owner on Feb 11, 2020. 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.
better support for binary projects for shaded libraries like wagon-ht…
…tp-2.10-shaded.jar Signed-off-by: Igor Fedorenko <igor@ifedorenko.com>
- Loading branch information
1 parent
8c6fad4
commit b4f88cc
Showing
5 changed files
with
82 additions
and
6 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
...ect/src/com/ifedorenko/m2e/binaryproject/sourcelookup/BinaryProjectContainerResolver.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,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; | ||
} | ||
} |
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
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
typo resovleSourceContainer --> resolveSourceContainer
Still time to fix it before releasing a new version