Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 5619de398825878e68d0da1a8a7bc850ceffbdc4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*******************************************************************************
 * 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 org.eclipse.m2e.binaryproject.internal.sourcelookup;

import static org.eclipse.jdt.launching.sourcelookup.advanced.AdvancedSourceLookup.getClasspath;

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;
import org.eclipse.jdt.launching.sourcelookup.advanced.IWorkspaceProjectDescriber;
import org.eclipse.jdt.launching.sourcelookup.containers.PackageFragmentRootSourceContainer;
import org.eclipse.m2e.binaryproject.internal.BinaryProjectPlugin;

public class BinaryProjectDescriber implements IWorkspaceProjectDescriber {

  static File getBinaryLocation(IProject project) throws CoreException {
    if (!project.isOpen()) {
      return null;
    }
    final String binaryLocation = project.getPersistentProperty(BinaryProjectPlugin.QNAME_JAR);
    if (binaryLocation == null) {
      return null;
    }
    return new File(binaryLocation);
  }

  @Override
  public void describeProject(IJavaProject project, IJavaProjectSourceDescription description) throws CoreException {
    final File binaryLocation = getBinaryLocation(project.getProject());
    if (binaryLocation == null) {
      return;
    }

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

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

    description.addDependencies(classpath);
    description.addLocation(binaryLocation);
    description.addSourceContainerFactory(() -> new PackageFragmentRootSourceContainer(binary));
  }

}

Back to the top