This repository has been archived by the owner on Oct 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
/
RecipeBundleProject.java
91 lines (73 loc) · 3.05 KB
/
RecipeBundleProject.java
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/**
* Copyright (c) 2016 Tasktop Technologies, Salesforce and others.
* 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:
* Gunnar Wagenknecht - initial API and implementation
*/
package org.eclipse.ebr.tycho.extras.plugin;
import static java.util.Objects.requireNonNull;
import java.io.File;
import javax.inject.Inject;
import javax.inject.Named;
import org.eclipse.tycho.ArtifactKey;
import org.eclipse.tycho.ReactorProject;
import org.eclipse.tycho.core.ArtifactDependencyWalker;
import org.eclipse.tycho.core.osgitools.AbstractTychoProject;
import org.eclipse.tycho.core.osgitools.BundleReader;
import org.eclipse.tycho.core.osgitools.OsgiManifest;
import org.eclipse.tycho.core.shared.TargetEnvironment;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.project.MavenProject;
/**
* Hook into Tycho allowing an EBR project to be treated as a Tycho project.
*/
@Named("eclipse-bundle-recipe")
public class RecipeBundleProject extends AbstractTychoProject {
private static final String CTX_ARTIFACT_KEY = RecipeBundleProject.class.getName() + "/bundleRecipe/artifactKey";
private final BundleReader bundleReader;
@Inject
public RecipeBundleProject(final BundleReader bundleReader) {
this.bundleReader = requireNonNull(bundleReader, "BundleReader is required!");
}
@Override
public ArtifactKey getArtifactKey(final ReactorProject project) {
// this relies on #setupProject being called
final ArtifactKey key = (ArtifactKey) project.getContextValue(CTX_ARTIFACT_KEY);
if (key == null)
throw new IllegalStateException("Project has not been setup yet " + project.toString());
return key;
}
private File getBuildDirectory(final MavenProject project) {
return new File(project.getBuild().getDirectory());
}
@Override
public ArtifactDependencyWalker getDependencyWalker(final MavenProject project) {
throw new IllegalStateException("not implemented");
}
@Override
public ArtifactDependencyWalker getDependencyWalker(final MavenProject project, final TargetEnvironment environment) {
throw new IllegalStateException("not implemented");
}
private OsgiManifest getManifest(final MavenProject project) {
return bundleReader.loadManifest(new File(getBuildDirectory(project), "MANIFEST.MF"));
}
public String getManifestValue(final String key, final MavenProject project) {
return getManifest(project).getValue(key);
}
public ArtifactKey readArtifactKey(final File location) {
final OsgiManifest mf = bundleReader.loadManifest(location);
return mf.toArtifactKey();
}
@Override
public void setupProject(final MavenSession session, final MavenProject project) {
// FIXME this might not work, i.e. a manifest might not exist yet
// instead we should build the ArtifactKey based on known values (POM)
final ArtifactKey key = getManifest(project).toArtifactKey();
project.setContextValue(CTX_ARTIFACT_KEY, key);
}
}