use of org.eclipse.m2e.core.embedder.ArtifactKey in project bndtools by bndtools.
the class AbstractMavenRepository method guessBundleFile.
File guessBundleFile(IMavenProjectFacade projectFacade) {
String buildDirectoryGuess;
IProject project = projectFacade.getProject();
IPath outputLocation = projectFacade.getOutputLocation();
if (outputLocation.segment(0).equals(project.getFullPath().segment(0))) {
outputLocation = outputLocation.removeFirstSegments(1);
}
IFolder folder = project.getFolder(outputLocation.toString());
if (folder.exists()) {
outputLocation = folder.getLocation();
}
if (outputLocation != null) {
if (outputLocation.lastSegment().equals("classes")) {
outputLocation = outputLocation.removeLastSegments(1);
}
buildDirectoryGuess = outputLocation.toOSString();
} else {
buildDirectoryGuess = projectFacade.getProject().getLocation().toOSString() + "/target";
}
ArtifactKey artifactKey = projectFacade.getArtifactKey();
String finalNameGuess = buildDirectoryGuess + "/" + artifactKey.getArtifactId() + "-" + artifactKey.getVersion() + ".jar";
return new File(finalNameGuess);
}
use of org.eclipse.m2e.core.embedder.ArtifactKey in project eclipse.jdt.ls by eclipse.
the class DependencyUtil method getArtifact.
public static File getArtifact(String groupId, String artifactId, String version, String classifier) throws FileNotFoundException, CoreException {
ArtifactKey key = new ArtifactKey(groupId, artifactId, version, classifier);
File archive = getLocalArtifactFile(key);
if (archive == null) {
Artifact artifact = MavenPlugin.getMaven().resolve(key.getGroupId(), key.getArtifactId(), key.getVersion(), "jar", key.getClassifier(), null, new NullProgressMonitor());
if (artifact == null) {
throw new FileNotFoundException("Unable to find " + key);
}
archive = getLocalArtifactFile(key);
}
return archive;
}
use of org.eclipse.m2e.core.embedder.ArtifactKey in project eclipse.jdt.ls by eclipse.
the class MavenSourceDownloader method discoverSource.
@Override
public void discoverSource(IClassFile classFile, IProgressMonitor monitor) throws CoreException {
if (classFile == null) {
return;
}
IJavaElement element = classFile;
while (element.getParent() != null) {
element = element.getParent();
if (element instanceof IPackageFragmentRoot) {
final IPackageFragmentRoot fragment = (IPackageFragmentRoot) element;
IPath attachmentPath = fragment.getSourceAttachmentPath();
if (attachmentPath != null && !attachmentPath.isEmpty() && attachmentPath.toFile().exists()) {
break;
}
if (fragment.isArchive()) {
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(fragment.getPath());
IPath path = file.getFullPath();
if (path == null || !path.toFile().exists()) {
path = file.getLocation();
if (path == null) {
return;
}
}
Boolean downloaded = downloadRequestsCache.getIfPresent(path.toString());
if (downloaded == null) {
downloadRequestsCache.put(path.toString(), true);
ArtifactKey artifact = new MavenPropertiesIdentifier().identify(path, monitor);
if (artifact == null) {
artifact = new MavenCentralIdentifier().identify(path, monitor);
}
if (artifact != null) {
if (!ProjectUtils.isMavenProject(element.getJavaProject().getProject())) {
// see https://github.com/eclipse-m2e/m2e-core/commit/b547ecc358c990e182a5eaf8d36f121e43f4a8c9#diff-3967743078be6a24ba1e3ec28bfc22bdf2c88a740695411f6d20e2444fef042fR943
long lastModified;
try {
File artifactFile = DependencyUtil.getArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getClassifier());
lastModified = artifactFile.lastModified();
} catch (FileNotFoundException | CoreException e1) {
lastModified = -1;
}
if (lastModified > -1) {
try {
File sources = DependencyUtil.getSources(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion());
sources.setLastModified(lastModified - 1);
} catch (FileNotFoundException | CoreException e) {
// ignore
}
try {
File javadoc = DependencyUtil.getJavadoc(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion());
javadoc.setLastModified(lastModified - 1);
} catch (FileNotFoundException | CoreException e) {
// ignore
}
}
}
BuildPathManager buildpathManager = (BuildPathManager) MavenJdtPlugin.getDefault().getBuildpathManager();
buildpathManager.scheduleDownload(fragment, artifact, true, true);
JobHelpers.waitForDownloadSourcesJobs(MAX_TIME_MILLIS);
}
}
break;
}
}
}
}
use of org.eclipse.m2e.core.embedder.ArtifactKey in project eclipse.jdt.ls by eclipse.
the class MavenCentralIdentifier method extractKey.
private ArtifactKey extractKey(JsonObject modelNode) {
JsonObject response = modelNode.getAsJsonObject("response");
if (response != null) {
int num = response.get("numFound").getAsInt();
if (num > 0) {
JsonArray docs = response.getAsJsonArray("docs");
String a = null, g = null, v = null;
for (JsonElement d : docs) {
JsonObject o = d.getAsJsonObject();
a = o.get("a").getAsString();
g = o.get("g").getAsString();
v = o.get("v").getAsString();
if (a != null && g != null && v != null) {
return new ArtifactKey(g, a, v, null);
}
}
}
}
return null;
}
use of org.eclipse.m2e.core.embedder.ArtifactKey in project eclipse.jdt.ls by eclipse.
the class MavenPropertiesIdentifier method getArtifactFromPomProperties.
private ArtifactKey getArtifactFromPomProperties(ZipFile jar) throws IOException {
// $NON-NLS-1$
ZipEntry mavenEntry = jar.getEntry("META-INF/maven");
if (mavenEntry == null) {
return null;
}
String jarName = jar.getName();
String entryName = mavenEntry.getName();
Enumeration<? extends ZipEntry> zipEntries = jar.entries();
ArtifactKey artifact = null;
while (zipEntries.hasMoreElements()) {
ZipEntry zipEntry = zipEntries.nextElement();
if (zipEntry.getName().endsWith("pom.properties") && zipEntry.getName().startsWith(entryName)) {
Properties props = new Properties();
props.load(jar.getInputStream(zipEntry));
String groupId = props.getProperty("groupId");
String artifactId = props.getProperty("artifactId");
String version = props.getProperty("version");
String classifier = props.getProperty("classifier");
if (groupId != null && artifactId != null && version != null) {
ArtifactKey currentArtifact = new ArtifactKey(groupId, artifactId, version, classifier);
if (artifact == null) {
artifact = currentArtifact;
} else {
// eg. org.fusesource.jansi:jansi:1.6
if (jarName.contains(artifactId + "-" + version)) {
artifact = currentArtifact;
}
}
}
}
}
return artifact;
}
Aggregations